dropdown menu in gridview returning only first value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Raghav123
    New Member
    • Jan 2014
    • 1

    dropdown menu in gridview returning only first value

    Hi,

    The DropDown menu in my GridView is only returning the first value.

    Here is my code:
    Code:
    <asp:GridView ID="GridView1"  CssClass = "Grid"  runat="server" 
                OnRowDataBound="OnRowDataBound" OnRowCommand="OnRowCommand" 
                 BackColor="White" BorderColor="#CCCCCC" 
                BorderStyle="None" BorderWidth="1px" CellPadding="3" Height="172px" 
                 Width="1314px" AutoGenerateColumns="False"  > 
      <asp:TemplateField HeaderText="Select Month">
        <ItemTemplate> 
          <asp:DropDownList ID="DropDownList1" DataValueField = "Value" runat="server" > 
            <asp:ListItem  Value="January">January</asp:ListItem> <asp:ListItem  Value="February">February</asp:ListItem> <asp:ListItem  Value="March">March</asp:ListItem> <asp:ListItem>April</asp:ListItem> <asp:ListItem>May</asp:ListItem> <asp:ListItem>June</asp:ListItem> <asp:ListItem>July</asp:ListItem> <asp:ListItem>August</asp:ListItem> <asp:ListItem>September</asp:ListItem> <asp:ListItem>October</asp:ListItem> <asp:ListItem>November</asp:ListItem> <asp:ListItem>December</asp:ListItem>
          </asp:DropDownList> 
        </ItemTemplate> 
      </asp:TemplateField>
    On button click event in gridview the row property is updated but DropDownMenu is returning first value

    C# coding
    Code:
     protected void OnRowCommand(object sender, GridViewCommandEventArgs e)
        {
                   if (e.CommandName == "Sub")
                {
                   ;
                    string Mont = ((DropDownList)GridView1.SelectedRow.FindControl("DropDownList1")).SelectedItem.ToString();
                       
        }
    Last edited by Frinavale; Jan 20 '14, 05:50 PM. Reason: Broke up the code tags so that asp.net code is in one chunk and C# code is in another code chunk. Also, removed white space in the C#code to make it easier to read.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Could you please post the code you have in your Page Load event and if you have any code in your Page Init event post that as well.

    -Frinny

    Comment

    Working...