RowDataBind事件未在回发时触发 [英] RowDataBind Event not firing on postback

查看:145
本文介绍了RowDataBind事件未在回发时触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我对GridView有问题.我正在使用gridview.in创建座位布局,因为我正在动态绑定每个单元格中的文本框.第一次一切都很好,即当我单击按钮时,gridview与所需的布局绑定了.页面发回时,未触发rowdatabound事件.有人可以帮我解决此问题.
在此先感谢
我的代码如下

Hi,
I Have a problem with GridView.I am Creating seating layout using gridview.in that I am binding textboxes in each cell dynamically.Every thing is ok for first time i.e when i am clicking button the gridview is binding with required layout.But problem is when the page is post back the rowdatabound event is not firing.Can any one help me For this issue.
Thanks in advance
My code is as follows

//for binding Grid
 protected void getdata()
    {
        try
        {
            DataTable dt = new DataTable();

            for (int i = 0; i < int.Parse(txtcolumns.Text); i++)
            {
                DataColumn dcol = new DataColumn();
                //dcol.AutoIncrement = true;
                dt.Columns.Add(dcol);

            }
            for (int i = 0; i < int.Parse(txtrows.Text); i++)
            {
                DataRow dr = dt.NewRow();
                dt.Rows.Add(dr);
            }
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        catch (Exception ex)
        {
            lblerror.Visible = true;
            lblerror.Text = ex.Message;
        }
    }


-----------------


-----------------

//Rowdatabound
 try
        {
            int inte = e.Row.RowIndex + 1;
            if (cbxseats.Checked == true)
            {
                if (inte == int.Parse(txtdivider.Text))
                {

                    if (e.Row.RowType == DataControlRowType.DataRow)
                    {
                        for (int i = 0; i < int.Parse(txtcolumns.Text); i++)
                        {
                            TextBox tbx = new TextBox();
                            tbx.Width = 40;
                            tbx.Height = 20;
                            tbx.ID = "txtbox" + inte + i;
                            //tbx.Text = "45";
                            //tbx.ReadOnly = true;
                            if (i + 1 == int.Parse(txtcolumns.Text))
                            {
                                e.Row.Cells[i].Controls.Add(tbx);
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < int.Parse(txtcolumns.Text); i++)
                    {
                        if (e.Row.RowType == DataControlRowType.DataRow)
                        {
                            TextBox tbx = new TextBox();
                            tbx.Width = 40;
                            tbx.Height = 20;
                            tbx.ID = "txtbox" + inte + i;
                            e.Row.Cells[i].Controls.Add(tbx);
                        }
                    }
                }
            }
            else if (cbxbearths.Checked == true)
            {
                
                if (inte == int.Parse(txtdivider.Text))
                {

                    if (e.Row.RowType == DataControlRowType.DataRow)
                    {
                        e.Row.Cells[0].Controls.Add(new LiteralControl("<br/>"));
                       
                    }
                }
                else
                {
                    for (int i = 0; i < int.Parse(txtcolumns.Text); i++)
                    {
                        if (e.Row.RowType == DataControlRowType.DataRow)
                        {
                            TextBox tbx = new TextBox();
                            tbx.Width = 80;
                            tbx.Height = 20;
                            tbx.ID = "txtbox" + inte + i;
                            e.Row.Cells[i].Controls.Add(tbx);
                        }
                    }
                }

            }
catch (Exception ex)
      {
          lblerror.Visible = true;
          lblerror.Text = ex.Message;
      }
  }


------------


------------

//on button click event i am calling that getdata() to bind the gridview
protected void btnlayout_Click(object sender, EventArgs e)
   {
       try
       {
               getdata();
               lbllower.Visible = true;
               //btnupperdeck_Click(sender, e);
       }
       catch (Exception ex)
       {
           lblerror.Visible = true;
           lblerror.Text = ex.Message;
       }
   }

推荐答案

DataTable dt = new DataTable();


您每次都在getData中生成新表,那么如何期望它被数据填充.
它始终是空白表,并且只会出现空行.


You are generating new table everytime in getData, then how can you expect it to be filled with data.
It will always be blank table, and you''ll come up with empty rows only.


这篇关于RowDataBind事件未在回发时触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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