how to get value of dropdownlist which is inside a gridview on the click of a button?

Ram Singh picture Ram Singh · Sep 12, 2011 · Viewed 8.6k times · Source

I have a dropdownlist inside the gridview. Now i want when i click on a button then i can check the value of dropdownlist. I have fired rowcommand event of gridview for it but debugger is not able to go reach there..Please help me..My Code is

  Protected Sub grd_Test_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grd_Test.RowCommand
    If e.CommandName = "Select" Then


     End If
End Sub

my Source code is

   <asp:GridView ID="grd_UnAssignProperties" runat="server" AutoGenerateColumns="False"><Columns>
                    <asp:TemplateField HeaderText="Assign To">
                        <ItemTemplate>
                            <asp:DropDownList ID="drp_UnAssignProp" runat="server">

                            <asp:ListItem  Value="" >Default</asp:ListItem>
                            </asp:DropDownList>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns></asp:GridView><tr><td><asp:Button ID="btn_Save" runat="server" CommandName="Select" Text="Submit"  />

Answer

i100 picture i100 · Sep 12, 2011

try this

DropDownList ddl = (DropDownList)GridView1.Rows[e.RowIndex].Cells[0].FindControl("drp_UnAssignProp");
string val = ddl.SelectedValue;