protected void gdvList_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dropdownList = new DropDownList();
dropdownList.DataSource = addressList;
dropdownList.DataTextField = "Name";
dropdownList.DataValueField = "ID";
dropdownList.DataBind();
TableCell tc = new TableCell();
tc.CssClass = "grid-content left";
tc.Width = 60;
tc.Controls.Add(dropdownList);
e.Row.Cells.AddAt(3, tc);
}
}问题是control能加在第3列,可是原有的cell向右移了一个,导致每行cell数量比gridview columns数量多一个。如何替换当前cell,不是加一个。
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dropdownList = new DropDownList();
dropdownList.DataSource = addressList;
dropdownList.DataTextField = "Name";
dropdownList.DataValueField = "ID";
dropdownList.DataBind();
TableCell tc = new TableCell();
tc.CssClass = "grid-content left";
tc.Width = 60;
tc.Controls.Add(dropdownList);
e.Row.Cells.AddAt(3, tc);
}
}问题是control能加在第3列,可是原有的cell向右移了一个,导致每行cell数量比gridview columns数量多一个。如何替换当前cell,不是加一个。
解决方案 »
- 急急急,请各位帮我写一段关于调用存储过程分页的代码,要求返回的是list
- masterpage中的 js问题
- ASP.NET播放音频,播放完一首播放下一首的好方法,等待中…
- 求GridView关于模板列 (在线等)
- 关于Ajax的回执函数传递参数的问题!
- |M| 为什么我的VS2005 配置了Web.config 的requestEncoding="gb2312" 后后台读取的数据就成乱码了 谢谢 在线马上结
- 如何给DataGrid的列标头加中文,这个B/S很容易实现,但是,不知道C/S模式(即windows form) 下如何实现!!!!
- 如何实现如下效果?
- .net程序,客户端可以用ie5浏览吗?
- Label问题
- sql文件的存储形式和位置。
- 跪求在 asp.net中有4个文本框,验证至少填写其中3个才能进行查询,内容如下:请高手解答
改成
e.Row.Cells[3].Controls.Add(dropdownList);不要增加 TableCell 了
e.Row.Cells.AddAt(3, tc)
后面加上
e.Row.Cells.RemoveAt(_cellIndex + 1);
又会出现另外一个问题。click button后,
报错,control 的数量和位置在postback时,和以后还必须一样。Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.