如何在edititemtemplate中获取下拉列表的选定值 - datagridview?

时间:2013-04-15 10:25:08

标签: c# asp.net gridview drop-down-menu

我在DataGrid EditItemTemplate中创建了一个DropDownList。 (手动)

<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="SqlDataSource1" DataTextField="nazwa" DataValueField="nazwa" 
                        SelectedValue='<%# Bind("nazwa") %>'>
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:baza_pismConnectionString1 %>" 
                        SelectCommand="SELECT [nazwa] FROM [podmioty]"></asp:SqlDataSource>
</EditItemTemplate>

如何从后面的代码中的下拉列表中获取所选值?

1 个答案:

答案 0 :(得分:1)

我想你想在编辑过程中找到下拉列表的值,这段代码会做

    protected void gridview1_RowEditing(object sender, GridViewEditEventArgs e)
        {
GridViewRow row = gridview1.Rows[e.RowIndex];

            DropDownList ddl = row.FindControl("DropDownList1") as DropDownList;
        var value=ddl.SelectedValue;
            //now do whatever with that value
        }