您的位置:首页 > 其它

GridView中获得控件的引用的方法

2011-01-15 20:35 274 查看
1.如下图所示的一个Gridview 控件,当点击编辑时出现图2:



图1



图2

当我们点击[更新]按钮时获取方框和下拉菜单的值的方法:

DropDownList dl = GridView1.Rows[e.RowIndex].Cells[2].Controls[1] as DropDownList;
TextBox tb = GridView1.Rows[e.RowIndex].Cells[1].Controls[1] as TextBox;
int id = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
int cpid = Int32.Parse(dl.SelectedValue);
new Hntjxh.BLL.Category().UpdateCategory(id, tb.Text, cpid);
GridView1.EditIndex = -1;
BindCategoryTableValue();


注意”GridView1.Rows[e.RowIndex].Cells[1].Controls[1]“这一行,要取Controls[1]而不是0,通过试验得知Controls[0]是一个System.Web.UI.Liter alControl类型的控件,Controls[1]才是我们想要的控件!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: