views:

1519

answers:

4

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?

+1  A: 

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.
Goblyn27
I got through your step one fine and I was able to access the selected value of the dropdownlist. However, my dropdownlist does not have a part property. ddl.part???
Eric
Sorry man, that was a bad typo on my part. That should have read "Access the parent property"
Goblyn27
could you possibly post some code. I've never really seen this method before. Just code that could give me a general idea.
Eric
OK, I am at work which is why I cant give very good example source code. I have to do it all in my head =) But I will try in another answer to this post
Goblyn27
I'll give you another +1 for your time.
Eric
+1  A: 

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;
Goblyn27
I think i am going to take a different approach. I've tried this and I understand the concept;it just doesn't seem to work in this situation. I'll post the answer when i figure it out. Thanks! +1
Eric
A: 

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))
A: 

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;

Falak