ASP

本类阅读TOP10

·asp常用数据库连接方法和技巧
·无组件生成BMP验证码
·一些常用的辅助代码 (网络收藏)
·JavaScript实现的数据表格:冻结列、调整列宽和客户端排序
·VisualStudio.NET_2003及其 MSDN 下载地址
·ASP模拟MVC模式编程
·图片以二进制流输出到网页
·MD5加密算法 ASP版
·ASP.NET编程中的十大技巧
·改进 ASP 的字符串处理性能

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
(论坛答疑点滴)怎么触发DataGrid模板列中控件的事件?

作者:未知 来源:月光软件站 加入时间:2005-5-13 月光软件站

有很多网友遇到这样的问题:在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就是这个下拉框,类型转换一下就能使用了




相关文章

相关软件