获取动态下拉列表选择的选定行索引
-
06-09-2019 - |
题
我知道这个问题有点不稳定,也许有误导性,但我有一个网格视图,行上有下拉列表。我为 SelectedIndexChanged 创建了一个 AddHandler 和一个委托,它到达了子目录。这是代码:
AddHandler ddlmgr.SelectedIndexChanged, AddressOf ddlmgr_SelectedIndexChanged
Public Delegate Sub DropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As DropDownList_SelectedIndexChanged)
Protected Sub ddlmgr_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
End Sub
如果未调用 GridView_RowCommand,如何获取行的 Id?
解决方案
大工作 工作绝对没问题,我
DropDownList ddl = (DropDownList)sender;
Control p = ddl.Parent;
//you are going to loop because the immediate
//parent may not be the repeater item but instead a
//container control of some kind (say a template)
while (p.GetType() != typeof(RepeaterItem))
{
p = p.Parent;
if (p == null)
return; //we have reached the top of the control tree
}
RepeaterItem ri = (RepeaterItem)p;
int index = ri.ItemIndexreturn index;
其他提示
您将需要做一些跑腿工作,因为如果不写出代码并在此处自行测试,我无法提供 100% 的细节,目前我无法做到这一点,但代码应该遵循这些思路。
在 ddlmgr_SelectedIndexChaged 内,
- 将您的发件人投射到 DropDownList
- 访问下拉列表的部分属性。
- 检查它是一个 GridItem (或 Repeateritem 或任何一个,你明白的)
- 如果是,则获取项目 itemindex。如果不访问其父属性。
- 继续,直到找到 Row 对象。
希望这有助于。如果不是这样,也许有人多一点自由访问可以附和
DropDownList ddl = (DropDownList)sender;
Control p = ddl.Parent;
//you are going to loop because the immediate
//parent may not be the repeater item but instead a
//container control of some kind (say a template)
while (p.GetType() != typeof(RepeaterItem))
{
p = p.Parent;
if (p == null) return; //we have reached the top of the control tree
}
RepeaterItem ri = (RepeaterItem)p;
int index = ri.ItemIndex
return index;
的DropDownList ddltxt =(DropDownList的)发送者; 串TEMP2 = ddltxt.SelectedItem.Text; 串TEMP3 = ddltxt.SelectedItem.Value; 串温度= ddltxt.ID.ToString(); INT strlength = temp.Length; 串strLastchar = temp.Substring(strlength - 1,1); INT intlastchar = int.Parse(strLastchar.ToString()); 串commonpart = temp.Substring(0,strlength - 1);
if (intlastchar == 1)
{
string targetdropdownid = commonpart + "2";
DropDownList targetlist = (DropDownList)TableRow11.FindControl(targetdropdownid);
using (conn = new SqlConnection(ConnectionString))
不隶属于 StackOverflow