Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

Getting row from datagrid a dropdown posted from?


hello, new to .Net (using c#). I have a datagrid and in one of the columns a dropdownlist that's populated when iterating through the each of the items. An initialize component is called when the postback occurs from a dropdown in any of the given rows. Problem is, how can I tack on some extra information to it from the row to know which dropdownlist to get the data from? I can easily iterate through them all in the grid, but I'm mkaing an update to the database when this happens and obviously I'd only want to do this when necassary. Here is some of my code:

the asx itemtemplate:

<asp:BoundColumn HeaderText="ITEM" DataField="product_shortdesc" HeaderStyle-CssClass="addressHeaderPaddedLeft" ItemStyle-CssClass="addressListItemPaddedLeft" />

<asp:TemplateColumn HeaderText="<table cellspacing='0' cellpadding='0' border='0' width='100%'><tr><td align='center' style='font-size:11px' width='95%'>ALTERNATE GIFT</td><td align='right'><a href=''><img src='images/icon_alternate_question.gif' border='0'></a></td></tr></table>" HeaderStyle-BackColor="#C7BEAD" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center">
<ItemTemplate>
<asp:DropDownList ID="_DdAlternative" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>

and here is the initialized component:

this._DdAlternative.SelectedIndexChanged += new System.EventHandler(this.ProductChanged);

So, when in the ProductChanged method I can't just simply call the name of the control because each one has a unique identifer tacked concatenated with the name to identify it, so essentially at this point just _DdAlternative doesn't even exist. So, how can I pass some other variable from the same row into the method that will tell me which drop down I'm looking at. Or, without passing something else in, how can I just figure that out??

thanks in advance!! time sensitive issue for me..
0
animated405
Asked:
animated405
  • 2
1 Solution
 
praneethaCommented:
     <asp:DropDownList id="DdAlternative" runat="server" Width="134px" AutoPostBack="True" OnSelectedIndexChanged="DropDown_SelectedIndexChanged">


in codebehind

protected void DropDown_SelectedIndexChanged(object sender, EventArgs e)
            {
                  DropDownList list = (DropDownList)sender;

                  TableCell cell = list.Parent as TableCell;
                  DataGridItem item = cell.Parent as DataGridItem;

                  int index = item.ItemIndex;
                  string content = item.Cells[0].Text;

                  Response.Write(
                        String.Format("Row {0} contains {1}", index, content)
                        );
   
            }



http://odetocode.com/Articles/231.aspx

good luck
0
 
animated405Author Commented:

thanks!!
0
 
praneethaCommented:
u r welcome. thanks for the points :)

good luck
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now