误差与动态的LinkBut​​ton的事件处理程序 [英] Error with the event handlers of dynamic linkbutton

查看:149
本文介绍了误差与动态的LinkBut​​ton的事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检索取决于texboxes输入和在一个数据表中存储来自数据库的数据,之后再从数据表中即时发送数据到动态表和在面板中显示的表,在表中的第一列的所有数据都linkbuttons的我写的事件处理程序的动态链接按钮,但事件处理函数不是触发了,我要存储在事件处理函数的字符串LinkBut​​ton的文字,但事件处理函数不是触发。

I am retrieving data from database depending upon the texboxes input and storing in a datatable , after then from datatable im sending data into dynamic table and displaying table in a panel,in the table all the data of the first column are of linkbuttons, i wrote event handler for dynamic link buttons , but the event handler is not triggering, and i want to store the linkbutton text in a string in the event handler, but the event handler is not triggering.

code:

protected void Button1_Click(object sender, EventArgs e)
{
   // GridView1.
    DataTable dt = new DataTable();

    OleDbConnection con = new OleDbConnection(str);
    con.Open();
    OleDbCommand cmd = new OleDbCommand();
    cmd.Connection = con;
    cmd.CommandText = "select ID,title,desc from [SO] where ID='" + TextBox1.Text.ToString() + "'or title='" + TextBox2.Text.ToString() + "'";
    OleDbDataAdapter db = new OleDbDataAdapter(cmd);
    db.Fill(dt);
    Table tb = new Table();
    tb.BorderColor = Color.Black;
    tb.BorderWidth = 2;

    DataRow dr;
    for (int i = 0; i < dt.Rows.Count; i++)
    {

        TableRow tr = new TableRow();
        tr.BorderColor = Color.Black;
        tr.BorderWidth = 2;
        tr.ID = "tr" + i;
        TableCell tc = new TableCell();
        tc.BorderColor = Color.Black;
        tc.BorderWidth = 2;
        tc.ID = "tc" + i;
        TableCell tc1 = new TableCell();
        tc1.BorderColor = Color.Black;
        tc1.BorderWidth = 2;
        tc1.ID = "tc1" + i;
        TableCell tc2 = new TableCell();
        tc2.BorderColor = Color.Black;
        tc2.BorderWidth = 2;
        tc2.ID = "tc2" + i;
        LinkButton t = new LinkButton();
        t.BorderColor = Color.Black;
        t.BorderWidth = 2;
        t.ID = "t" + i;
        t.Click += new EventHandler(t_edit);

        TextBox t1 = new TextBox();
        t1.BorderColor = Color.Black;
        t1.BorderWidth = 2;
        t1.ID = "t1" + i;
        TextBox t2 = new TextBox();
        t2.BorderColor = Color.Black;
        t2.BorderWidth = 2;
        t2.ID = "t2" + i;

        dr = dt.Rows[i];
        t.Text = Convert.ToString(dr["ID"]);
        t1.Text = Convert.ToString(dr["title"]);
        t2.Text = Convert.ToString(dr["desc"]);
        tc.Controls.Add(t);
        tc1.Controls.Add(t1);
        tc2.Controls.Add(t2);
        tr.Cells.Add(tc);
        tr.Cells.Add(tc1);
        tr.Cells.Add(tc2);
        tb.Rows.Add(tr);

    }
    Panel1.Controls.Add(tb);

}
protected void t_edit(object sender, EventArgs e)
{

}


K,但使用的会话概念IM检索总表,以便linkbuttons也检索了,我想添加一个按钮点击linkbttons,这里的问题是事件处理程序不assiging到LinkBut​​ton和IM按钮添加linkbuttons点击,而不是在页面加载。


k but by using the sessions concept im retrieving the total table so that the linkbuttons are also retrieving , and i want to add the linkbttons on a button click , here the problem is the eventhandler is not assiging to the linkbutton, and im adding linkbuttons on button click,not on page load.

推荐答案

您必须使用 Page_Init 的Page_Load 事件处理程序编写code动态创建控件。请阅读MSDN页面如何添加控件动态以及ASP.NET页面生命周期的文章。

You must have to use Page_Init or Page_Load event handler to write code that create controls dynamically. Please read MSDN pages on How to add controls dynamically and ASP.NET Page life cycle articles.

这篇关于误差与动态的LinkBut​​ton的事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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