探讨为GRIDVIEW中的控件动态添加事件

在使用ASP.NET开发网站时,遇到了GridView控件的问题。需要根据查询方式动态调整GridView列数,并添加ButtonField列。然而,为ButtonField的按钮绑定事件时遇到困难,事件无法正常绑定。代码示例展示了按拼音查询时的数据绑定情况。
摘要由CSDN通过智能技术生成

最近开始用asp.net来开发一个网站,其中用到了gridview控件.要实现根据不同的查询方式,使gridview绑定到不同的存储过程中,能动态的改变gridview列的个数,并添加一列 ButtonField.
但是在给 ButtonField中的button动态绑定事件的时候出现问题,事件根本绑定不上.
希望各位仁兄为小弟我解决一下这个问题啊
代码如下(下面只是实现按拼音方式查询时的数据绑定) 

 



public   partial   class  SearchResult : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!IsPostBack)
        
{
            SqlDataAdapter adapter 
= new SqlDataAdapter();
            DataSet dataset 
= new DataSet();
            SqlCommand command 
= new SqlCommand();
            
string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
            
using (SqlConnection connection = new SqlConnection(constr)) 
            
{
                command.CommandText 
= "按拼音姓名查询";
                command.CommandType 
= CommandType.StoredProcedure;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值