p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   gridview with a dropdown list (http://p2p.wrox.com/showthread.php?t=60360)

paullam71 July 22nd, 2007 09:43 AM

gridview with a dropdown list
I have a Search page that has a gridview. In the grid is a dropdown list. I select the dropdownlist option using OnSelectedIndexChanged. The option will transfer the user to another screen. This works fine. The issue I am having is when the user clicks Go Back. This is javascript and just goes back to the Search page. The original row is still selected. If the user selects another row (say below the original), the first row in the gridview always shows up in the OnSelectedIndexChanged. I thought (sender) would be the current row but I am not seeing that. What am I doing wrong? or does the GridView always start at the top?
Here is my aspx page:
                                <td><asp:GridView id="dgResults" runat="server" Width="100%" CssClass="text" BackColor="#DDDDFF" AutoGenerateColumns="False" OnRowDataBound="dgResults_Bound" OnSorting="dgResults_Sorting" AllowSorting="True" datakeynames="requestID" >
<asp:TemplateField HeaderText="Action">
<HeaderStyle Width="5%"></HeaderStyle>
<asp:DropDownList ID="ddlOptions" Runat="server" OnSelectedIndexChanged="ddlOptions_OnSelectedIndex Changed" AutoPostBack="true"/> </ItemTemplate> </asp:TemplateField>

Here is my code:
public void ddlOptions_OnSelectedIndexChanged(object sender, EventArgs e)
            DropDownList ddlOptions = (DropDownList)sender;
            GridViewRow gvr = (GridViewRow)ddlOptions.NamingContainer;

            string option = ddlOptions.SelectedValue;

            string requestID = dgResults.DataKeys[gvr.RowIndex].Value.ToString();

All times are GMT -4. The time now is 07:44 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.