我要将表中的数据都读到DataGrid中,但列数太多了,我就在最后三列的HeaderTemplate中分别添加了三个下拉菜单,想实现这三列的内容由下拉菜单里面用户选择的列名决定。
怎样做哦????
怎样做哦????
解决方案 »
- 网站自动多出一个目录
- .htm页面如何使用.net中的.master模板,可以吗
- C# timer 控件的用法
- 生成图片后,image里却显示不了实时的图片
- 怎么从sql中读取二进制图片到控件Image,求代码!
- System.Net.WebException: 无法连接到远程服务器 ---> System.Net.Sockets.SocketException: 由于目
- 讨论一下跨站点或跨应用程序共享session的解决方案?
- 300RMB,寻求一个系统3个功能模块的完善(有框架)!!!
- 急急!!asp.net程序打开oracle数据库的连接出错的怪问题???
- 怎么测试数据库是否连接成功
- 类库问题
- DataGrid控件中的ItemTemplate中有一CheckBox,如何点击它时,实现更新这一行记录
PlaceHolder1.Controls.Add(xx);用一个PlaceHolder看可以不可以,呵呵!
DropDownList xx=new DropDownList()
PlaceHolder1.Controls.Add(xx);
BoundField bf = new BoundField();
bf.DataField = "数据库中的字段名";
bf.DataFormatString = "{0:d}"; //字段显示格式,这里表示短日期
bf.HtmlEncode = false; //用到格式化字符串的话,就要把这个设为false
this.viewList.Columns.Add(bf); //viewList就是GridView网络控件
DropDownList的SelectedItem.Value设置为列的序号。
我用下面的方法,但选择DropDownList中的项时,不管DropDownList的AutoPostBack设为true还是false,没有反应.
private void ShowCol(DropDownList dp, DataGrid dg, int index)
{
if(Int32.Parse(dp.SelectedItem.Value) != index)
{
dg.Columns[Int32.Parse(dp.SelectedItem.Value)].Visible = true;
dg.Columns[index].Visible = false;
}
}DropDownList[] dps;private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Header)
{
DropDownList dp1 = (DropDownList)e.Item.FindControl( "dp1" );
DropDownList dp2 = (DropDownList)e.Item.FindControl( "dp2" );
DropDownList dp3 = (DropDownList)e.Item.FindControl( "dp3" );
DropDownList dp4 = (DropDownList)e.Item.FindControl( "dp4" );
DropDownList dp5 = (DropDownList)e.Item.FindControl( "dp5" );
DropDownList dp6 = (DropDownList)e.Item.FindControl( "dp6" );
DropDownList dp7 = (DropDownList)e.Item.FindControl( "dp7" );
DropDownList dp8 = (DropDownList)e.Item.FindControl( "dp8" );
dps = new DropDownList[8]{dp1, dp2,dp3,dp4, dp5, dp6, dp7, dp8};
for(int i = 1; i <= 8; i++)
{
this.ShowCol(dps[i - 1], this.DataGrid1, i+2);
}
}
}
-----------------
请各位想想办法。你们也做做,不要凭空乱造哈,真的会害死人的哦!!!
谢谢!