ASP.NET基础教程-DataGrid表格控件-处理在DataGrid中的DropDownList的事件
2007-10-11 09:46:59
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://chenxing.blog.51cto.com/240526/45824 |
DropDownList没有CommandName属性,所以不能用ItemCommand事件,解决方法如下:
1、在DataGrid的模板列中加入的DropDownList控件 <asp:DropDownList runat=“server” id=“ddl” AutoPostBack=“True” OnSelectedIndexChanged=“ddl_SelectedIndexChanged” /> 2、然后你在.aspx.cs中给DropDownList控件添加一个更改选定索引后激发事件 //下面的事件一定要声明成protected或者public,不能是private的。 protected void ddl_SelectedIndexChanged(object sender, System.EventArgs e) { //在事件中怎样得到本行其他Cell的值 //DataGrid完全是一个Table结构的控件,DataGrid包含DataGridItem,每个DataGridItem又包含TableCell,可以在TableCell的某个控件中,利用控件的Parent来得到TableCell,再利用TableCell的Parent,得到DataGridItem DropDownList ddl = (DropDownList)sender; TableCell cell = (TableCell)ddl.Parent; DataGridItem item = (DataGridItem)cell.Parent; Response.Write(item.Cells[0].Text); } ![]() |



晨星
博客统计信息
热门文章
最新评论
友情链接

