日期:2014-05-17  浏览次数:20552 次

如何在gridview中使用dropdown
gridview有一列 数据邦定到 store ID 字段,同时我想在这列显示store ID dropdown,dropdown 的数据源是一个method,

GetStoreID() , 这个 method 返回一个Store object List.

如何实现呢?

------解决方案--------------------
用模板列实现,很简单的

 <asp:TemplateField>
<ItemTemplate><asp:DropDownList ID="ddlStoreId" runat="server"></asp:DropDownList></ItemTemplate>
</asp:TemplateField>
------解决方案--------------------
后台

后台:
protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlStoreId = e.Row.FindControl("ddlStoreId") as DropDownList;
ddlStoreId.DataSource = GetStoreID();
ddlStoreId.DataTextField = "storeID";
ddlStoreId.DataValueField = "storeID";
ddlStoreId.DataBind();
}
}
------解决方案--------------------
后台:
DropDownList ddlStoreId = e.Row.FindControl("ddlStoreId") as DropDownList;
ddlStoreId.DataSource = GetStoreID();
ddlStoreId.DataTextField = "storeID";
ddlStoreId.DataValueField = "storeID";
ddlStoreId.DataBind();
------解决方案--------------------
例子
http://dotnet.aspx.cc/file/Add-Delete-Update-Edit-Data-With-Paging-in-GridView.aspx