Click here to Skip to main content
16,016,168 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
C#
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();
    }


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..
Posted
Updated 26-Feb-10 2:16am
v3

1 solution

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;
            }
}
}

but still am not quite sure that it will store correct value
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900