怎么触发DataGrid模板列中控件的事件?
2007-08-06 10:38
507 查看
有很多网友遇到这样的问题:在DataGrid模板列中的按钮可以触发ItemCommand事件但是怎么触发其他事件?(比如放置DropDownList怎么触发SelectedIndexChange事件?……)
按照/article/4593987.html我们进行一下修改:
在模板列中增加一个DropDownList
<asp:TemplateColumn HeaderText="学院">
<ItemTemplate>
<asp:DropDownList ID="dep2" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"></asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="dep" Runat="server"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
在前台直接加上事件DropDownList2_SelectedIndexChanged
然后在后台添加事件就可以了
protected void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{
Response.Write(((DropDownList)sender).SelectedItem);
}
注意,事件不能是private的,这里的sender就是这个下拉框,类型转换一下就能使用了
按照/article/4593987.html我们进行一下修改:
在模板列中增加一个DropDownList
<asp:TemplateColumn HeaderText="学院">
<ItemTemplate>
<asp:DropDownList ID="dep2" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"></asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="dep" Runat="server"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
在前台直接加上事件DropDownList2_SelectedIndexChanged
然后在后台添加事件就可以了
protected void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{
Response.Write(((DropDownList)sender).SelectedItem);
}
注意,事件不能是private的,这里的sender就是这个下拉框,类型转换一下就能使用了
相关文章推荐
- (论坛答疑点滴)怎么触发DataGrid模板列中控件的事件?
- (论坛答疑点滴)DataGrid模板列中控件的事件中怎么知道是哪行触发的事件?
- 怎么触发DataGrid模板列中控件的事件
- 怎么触发DataGrid模板列中控件的事件?
- DataGrid列头中添加CheckBox控件, HeaderSyle 在资源文件中,给模板中的控件添加事件
- MVVM-Light模式,在dataGrid的模板下,绑定事件不触发的原因已经服务端排序的实现
- DataGrid控件中模板列的服务器控件,怎么添加事件代码
- DataGrid模板列上的ImageButton 不能触发ItemCommand事件
- easyui的datagrid单击某一栏同时触发onClickRow和其中一栏的自定义事件怎么办?
- MVVM-Light模式,在dataGrid的模板下,绑定事件不触发的原因已经服务端排序的实现
- MVVM-Light模式,在dataGrid的模板下,绑定事件不触发的原因已经服务端排序的实现
- Asp.net中服务端控件事件是如何触发的?
- 客户端如何触发服务器端控件的事件
- Winform 点击TreeView控件节点的CheckBox不触发NodeMouseClick事件的做法
- asp.net中的按钮事件不触发页面验证控件
- 怎么把ShockWaveFlash控件上发生的鼠标右键捕获,并替换成鼠标左键事件
- DataGrid模板列的CheckBox事件定义方法
- 自定义控件中子控件如何触发字父控件的事件
- 关于页面中回车键默认触发某个控件按钮事件的问题(DefaultButton)
- Asp.net中服务端控件事件是如何触发的(笔记)