Solved

Getting row from datagrid a dropdown posted from?

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

816 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

8 Experts available now in Live!

Get 1:1 Help Now