Solved

Getting row from datagrid a dropdown posted from?

Posted on 2004-10-04
3
209 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

752 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