0

我在 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>

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

4

1 回答 1

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
        }
于 2013-04-15T10:30:41.177 回答