动态表和控件 [英] dynamic table and controls

查看:67
本文介绍了动态表和控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
    con.Open();
    PlaceHolder1.Controls.Clear();

    if (RadioButton1.Checked == true)
    {
        SqlDataReader r1 = default(SqlDataReader);
        SqlCommand cmd = new SqlCommand("Select * from userdet
                         where username  like N'%" + TextBox1.Text + "%'", con);
        cmd.Parameters.AddWithValue("@username", TextBox1.Text);
        r1 = cmd.ExecuteReader();
        int count = 1;
         Table tbl = new Table();
         PlaceHolder1.Controls.Add(tbl);

       do
        {


           while (r1.Read())
            {

                for(int i=0;i<count;i++)
                {
                    TableRow tr = new TableRow();
                     tr.BorderWidth.Equals(10);
                 //  for(int j=0;j<3;j++)
                //   {
                        TableCell tc = new TableCell();
                        TableCell tc1 = new TableCell();
                        TableCell tc2 = new TableCell();


                       TextBox txtBox = new TextBox();
                        TextBox txtBox1 = new TextBox();
                      //  TextBox txtBox2 = new TextBox();
                        LinkButton lnkbutton = new LinkButton();//Response.Write(r1.GetString(0) + "<br>");

                        txtBox.Text = r1[0].ToString();
                        txtBox1.Text = r1[13].ToString();
                        //txtBox2.Text = r1[1].ToString();
                        lnkbutton.Text = "edit";

                            Session["un"] = txtBox.Text;
                            // Session["un1"] = txtBox1.Text;
                            lnkbutton.PostBackUrl = "../sample/editp.aspx";

                     tc.Controls.Add(txtBox);
                     tc.Controls.Add(txtBox1);
                     tc.Controls.Add(lnkbutton);
            // Add the TableCell to the TableRow
                     tr.Cells.Add(tc);
                     tr.Cells.Add(tc);
                     tr.Cells.Add(tc);

    //    }
        // Add the TableRow to the Table
          tbl.Rows.Add(tr);
          }
         // count++;

            }
        } while (r1.NextResult());


        r1.Close();
        con.Close();
        cmd = null;
        r1 = null;
        con = null;
        //r1.Close();
    }



将创建表tbl,并创建单元格tc,并将文本框和链接按钮放置在单元格中.但是在单击链接按钮时,应将与链接按钮单元格相对应的文本框中的值分配给会话变量,并应将其导航到其他页面.为此,我需要帮助.请紧迫..



the table tbl is getting created and the cells tc are also created and the textbox and link buttons is placed in the cells. but while clicking the link button the value in the text box,which is corresponding to linkbutton cell should be assigned to session variable and it should be navigated to other page. for that i need help. plz am in urgency..

推荐答案

但是为什么要使用html表? 使用数据表和网格,将网格与数据表绑定,使用gridview rowcommand事件,这是更简单的方法.....

如果您真的要使用html表,则必须做更多的工作....

给表赋予"id"并设置runat ="Server",即使表成为服务器控件.

然后在下面的代码中做一些必要的更改....

But why are you using html table???
use datatable, and grid, bind the grid with datatable, use gridview rowcommand event it is much more easier way to do the thing.....

if you are really want to use html table then have to do some more work....

give "id" to the table and set runat="Server" i.e. make table a server control.

and then Do some necessory changes in following code....

Control ctrl;

Button btn;
foreach(ctrl in tablename.controls(0).controls(0).controls
{
   if (myControl is System.Web.UI.WebControls.Textbox)
            {
               session["value"]= (ctrl as textbox).text;
            }
}
}


但仍然不太确定它将存储正确的值


这篇关于动态表和控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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