Question

I know the question is a little choppy and perhaps misleading,but I have a gridview with dropdownlists on the rows. I created an AddHandler and a Delegate for the SelectedIndexChanged and it gets to the sub. Here is the code for that:

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

How can i get the row's Id if GridView_RowCommand is not called?

Was it helpful?

Solution

Great work Works absolutely fine for me

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;

OTHER TIPS

You will need to do a bit of the legwork as I cant provide 100% specifics without writing out the code and testing it on my own here, which I am unable to do at present, but the code should go along these lines.

within the ddlmgr_SelectedIndexChaged,

  1. cast your sender to a DropDownList
  2. access the part property of the dropdownlist.
  3. Check it is is a GridItem (or repeateritem or whichever, you get the idea)
  4. If so, get the items itemindex. If not access its parent property.
  5. Continue until you find your Row object.

Hopefully this helps. If not, perhaps someone with a bit more liberal access can chime in

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)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))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top