Solved

Getting row from datagrid a dropdown posted from?

Posted on 2004-10-04
3
205 Views
Last Modified: 2010-04-15

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
Comment
Question by:animated405
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
praneetha earned 500 total points
ID: 12220501
     <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
 

Author Comment

by:animated405
ID: 12223211

thanks!!
0
 
LVL 15

Expert Comment

by:praneetha
ID: 12226315
u r welcome. thanks for the points :)

good luck
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now