2013-04-15 39 views
0

我在DataGrid EditItemTemplate中創建了一個DropDownList。 (手動)如何在edititemtemplate - datagridview中獲取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> 

如何從後面的代碼中的下拉列表中獲取所選值?

+2

當u想要的設定值的下拉我的意思是,在此情況 –

+1

試着看的CommandName和CommandArgument屬性DropDownList和GridView的OnRowCommand屬性/事件。 – series0ne

回答

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 
     } 
+0

我有錯誤。名稱「行」並不存在於當前上下文中。 – user2265880

+0

更新了代碼 – Dolo

相關問題