ItemDataBound事件里给他赋值,如下:
ItemDataBound(...)
{
if(e.Item.ItemType==ListItemType.EditItem)
{
//绑数据
SqlCommand rencommand=new SqlCommand("select DeptID,DeptName from Dept",BDConn);
SqlDataReader renreader=rencommand.ExecuteReader();
((DropDownList)e.Item.Cells[5].FindControl("DeptList")).DataSource=renreader;
((DropDownList)e.Item.Cells[5].FindControl("DeptList")).DataTextField="DeptName";
((DropDownList)e.Item.Cells[5].FindControl("DeptList")).DataValueField="DeptID";
((DropDownList)e.Item.Cells[5].FindControl("DeptList")).DataBind();
}
ItemDataBound(...)
{
if(e.Item.ItemType==ListItemType.EditItem)
{
//绑数据
SqlCommand rencommand=new SqlCommand("select DeptID,DeptName from Dept",BDConn);
SqlDataReader renreader=rencommand.ExecuteReader();
((DropDownList)e.Item.Cells[5].FindControl("DeptList")).DataSource=renreader;
((DropDownList)e.Item.Cells[5].FindControl("DeptList")).DataTextField="DeptName";
((DropDownList)e.Item.Cells[5].FindControl("DeptList")).DataValueField="DeptID";
((DropDownList)e.Item.Cells[5].FindControl("DeptList")).DataBind();
}
解决方案 »
- 求助,如何把在C#textbox text数据串 保存在excel相应的cell里面
- 小弟使用多线程及异步回调碰到了困难
- 如何检测是否存在XX对象?
- vs2005新建的sql查询保存不了!!
- 关于 网页数据收集的 Windows Service 程序,清高手指点
- 在web中,toolbar中要用一些圆形的图片,可是它的button却是方形的,不知怎么解决,郁闷!!!
- 求助
- 请问在c#的类库和组件里有没有和vb里面的telnet组件实现功能相似的类或者组件??
- 请教一下:Access数据库的参数最大是多少?表的字段最大是多少?
- 请推荐好书
- How to drag-drop a picture box?
- Install Shield 的窗口大小设置
for (...)
{
(DropDownList)(DataGrid1...FindControl("DropDownList_ID")).Add.......;
//强制赋值 查找DataGrid中的控件
}