Solved

Getting row from datagrid a dropdown posted from?

Posted on 2004-10-04
3
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

630 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