(论坛答疑点滴)怎么触发DataGrid模板列中控件的事件?

翻译|其它|编辑:郝浩|2005-04-13 10:55:00.000|阅读 2224 次

概述:

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>


有很多网友遇到这样的问题:在DataGrid模板列中的按钮可以触发ItemCommand事件但是怎么触发其他事件?(比如放置DropDownList怎么触发SelectedIndexChange事件?……)
按照http://blog.csdn.net/LoveCherry/archive/2005/03/24/328455.aspx我们进行一下修改:
在模板列中增加一个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就是这个下拉框,类型转换一下就能使用了
 


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP