我知道这个问题有点不稳定,可能会产生误导,但我在行上有一个带有下拉列表的gridview。我为SelectedIndexChanged创建了一个AddHandler和一个Delegate,它到达了sub。这是代码:
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?
答案 0 :(得分:1)
你需要做一些小工作,因为我无法提供100%的细节,而无需自己编写代码并在我自己测试,我目前无法做到,但代码应该遵循以下几行
在ddlmgr_SelectedIndexChaged中,
答案 1 :(得分:1)
希望这会有所帮助。如果没有,也许有更多自由访问权限的人可以加入
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;
答案 2 :(得分:0)
DropDownList ddltxt =(DropDownList)sender; string temp2 = ddltxt.SelectedItem.Text; string temp3 = ddltxt.SelectedItem.Value; string temp = ddltxt.ID.ToString(); int strlength = temp.Length; string strLastchar = temp.Substring(strlength - 1,1); int intlastchar = int.Parse(strLastchar.ToString()); string commonpart = temp.Substring(0,strlength - 1);
if (intlastchar == 1)
{
string targetdropdownid = commonpart + "2";
DropDownList targetlist = (DropDownList)TableRow11.FindControl(targetdropdownid);
using (conn = new SqlConnection(ConnectionString))
答案 3 :(得分:0)
很棒的工作 对我来说绝对没问题
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;