Gridview下拉列表 [英] Gridview DropdownList
本文介绍了Gridview下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在gridview中添加了一列,即Dropdownlist
I added one column to gridview that is Dropdownlist
<asp:TemplateField HeaderText="ramesh" >
<ItemTemplate>
<asp:DropDownList ID="ddlName" DataTextField="job_desc"
Width="100" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
如何将datatable列绑定到该Gridview DropDownList列表.
How to bind datatable column to that Gridview DropDownList list.
推荐答案
在这里:
在ASP.NET 2.0(C#)中将DropDownList嵌套到Gridview [ ^ ]
就像这样:
Here you go:
Nesting the DropDownList to Gridview in ASP.NET 2.0(C#)[^]
It would be something like:
if (e.Row.RowType == DataControlRowType.DataRow)
{
categoryid = Int32.Parse(e.Row.Cells[0].Text);
expression = "categoryid = " + categoryid;
DropDownList ddl = (DropDownList)e.Row.FindControl("dropdownlist1");
DataRow[] rows = ds.Tables[0].Select(expression);
foreach (DataRow row in rows)
{
DataRow newrow = mytable.NewRow();
newrow["productid"] = row["productid"];
newrow["productname"] = row["productname"];
mytable.Rows.Add(newrow);
}
ddl.DataSource = mytable;
ddl.DataTextField = "productname";
ddl.DataValueField = "productid";
ddl.DataBind();
}
这篇关于Gridview下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文