如何在DataGrid中添加DropDownList控件,并为DropDownList添加数据 要求是根据DataGrid中某一项的数据来决定为DropDownList中的数据,应该如何实现啊?最好有代码,谢谢!~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundColumn DataField="field1"></asp:BoundColumn> <asp:BoundColumn DataField="field2"></asp:BoundColumn> <asp:TemplateColumn> <ItemTemplate> <FONT face="宋体"> <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList></FONT> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid>=======================#region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged); this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemIndex>-1) { string curID = e.Item.Cells[0].Text; DropDownList ddlst = e.Item.FindControl("DropDownList1") as DropDownList ; ddlst.DataSource = GetDataSource(curID); ddlst.DataBind(); } } private DataTable GetDataSource(string id) { DataTable dt = new DataTable(); //根据id决定绑定到dropdownlist的数据源 return dt; } VB.NET 2008自定义控件问题 asp.net疑难问题 请教学习过程 '-' 附近有语法错误。 Global.aspx如何用? Duwamish装了之后,卸载了IIS,结果再装装不上了! 我是ASP初学者,急需高人帮我断下代码.这个代码从上数第几行开始截断就是"公司名称搜索""公司网址"等搜索部分了? 如何在线打开WORD文件 FreeTextBox 1.6.3工具栏按钮显示不了 可恨的蓝波,可恨的冲击波 GridView中没有数据时怎样显示表头和分页数据行? 一次性将页面中所有TextBox的值清成空,将DropDownList的默认选中值为第一行????
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="field1"></asp:BoundColumn>
<asp:BoundColumn DataField="field2"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<FONT face="宋体">
<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList></FONT>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
=======================
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex>-1)
{
string curID = e.Item.Cells[0].Text;
DropDownList ddlst = e.Item.FindControl("DropDownList1") as DropDownList ;
ddlst.DataSource = GetDataSource(curID);
ddlst.DataBind();
}
} private DataTable GetDataSource(string id)
{
DataTable dt = new DataTable();
//根据id决定绑定到dropdownlist的数据源
return dt;
}