行数据绑定事件不会发生 [英] row data bound event not occur

查看:140
本文介绍了行数据绑定事件不会发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用行数据绑定,在其中我使用查询复选框值并获取vakue来检查复选框的真假.

但是没有用..

请帮助我,,
在此先感谢.....



i am using row databound in which i used query for checkbox value and get the vakue for checking checkbox for true or false.

but did not workk..

Please Help Me,,,
Thanks in advance.....



protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //{
            //    CheckBox chk = (CheckBox)e.Row.Cells[2].FindControl("CheckBox1");
            //    if (chk == null)
            //    {
            //        if (e.Row.Cells[1].Text =="1") //check for status column
            //            chk.Checked = true;
            //    }
            //}

            int i = 1;
            string s11 = "Select bit_indicator,category,sub_cat from document_rights where user_id='" + drop_user.SelectedItem.Value + "' and bit_indicator='" + i + "' and category='" + drop_cat.SelectedItem.Value + "' and sub_cat='" + drop_sub_cat.SelectedItem.Value + "'";
            SqlDataAdapter ad2 = new SqlDataAdapter(s11, c.getcon());
            DataSet ds2 = new DataSet();
            ad2.Fill(ds2);
            if (ds2.Tables[0].Rows.Count != 0)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chk = (CheckBox)e.Row.Cells[2].FindControl("CheckBox1");
                    if (chk == null)
                    {
                        if (e.Row.Cells[1].Text == "1") //check for status column
                            chk.Checked = true;
                    }

                }
            }
            else
            {

            }
        }
    }

推荐答案

行数据绑定事件未发生
完成datagrind.Databind()后,将触发此事件.在方法中放置断点,肯定会命中.

但没有用..
这里什么没用?不确定,但我想告诉您,绑定的每一行都会触发RowDataBound方法.因此,如果您的网格有5行,则此方法将被调用5次.现在,在每次行绑定调用中从DB访问数据的逻辑看起来都不正确.
此外,现在,您在数据集中获得了一些数据,然后您什么也不做.检查您的代码.调试并查看执行情况和编写的代码.
row data bound event not occur
This event will fire once you do have done datagrind.Databind(). Put breakpoint in the method, it surely will hit.

but did not workk..
What did not work here? Not sure on this but I would like to tell you that RowDataBound method will get triggered for every row it binds. So, if your grid has 5 rows then this method will be called 5 times. Now, the logic of accessing data from DB at every rowbound call does not look right.
Further, right now, you get some data in a dataset and then you are doing nothing. Check your code. DEBUG and have see the execution and what code you written.


这篇关于行数据绑定事件不会发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆