Hi all,
     i am developing web application in asp.net backend MS-Sql.<br/> i have to retrieve a particular table values for example table name "costomer" and its fields are "c_id,c_name,c_contactno" like that and when i retrieve this values, it should be bind the checkbox for UI. now i've code for generate check box but it is not working well. only display single column c_id or C_name or C_contact number. but, i have to display all (c_id,c_name,c_contactno). i don't know how to do this, if anyone know please help me.
      #region generate checkbox
            public void generateckbox()
            {
                try
                {
                    objAddValuesClass = new AddValuesClass();
                    table = new DataTable();
                    ds = new DataSet();

                    ds = objAddValuesClass.getmenuvalues();
                    table = ds.Tables[0];
                    for (int intControlIndex = 0; intControlIndex <=  table.Rows.Count - 1; intControlIndex++)
                    {
                            CheckBox chkList1;
                            chkList1 = new CheckBox();
                            chkList1.Text = table.Rows[intControlIndex][0].ToString();
                            //chkList1.ID = table.Rows[intControlIndex][1].ToString();
                            chkList1.Font.Name = "Verdana";
                            chkList1.Font.Size = 9;
                            PnlControl.Controls.Add(chkList1);
                            PnlControl.Controls.Add(new LiteralControl(""));
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception(exp.Message);
                }    
            }
            #endregion

Concatentate them into a string.

string s = c_id.toString() + " - " +  C_name.toString() + " - " + C_contact.toString();
chkList1.Text = s;
Mr.gamble but i need separate checkbox for all table_data fields(c_id,c_name,c_contact). for example

c_id        c_name        c_contact
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ckbox_val   ckbox_val     ckbox_val    

like that, but now it showed only one field "c_id", i need all..
Thank u Mr.ggamble, now i got the code, and this code is working fine 

this is the code


step1: connect with the database.

using System.Data.Sqlclient;
sqlconnection conn=new sqlconnection("server=....;user id=...;password=....");


step2: Enter the table name in a textbox,and displaying the table informationprotected void TextBox1_TextChanged(object sender, EventArgs e)
    {
     try
        {
            string s1 = TextBox1.Text;

           //passing a query to fetch the table from database,which is entered in TextBox

            string s2 = "select * from " + s1;
            SqlDataAdapter da = new SqlDataAdapter(s2, conn);
            da.Fill(ds);
            DataTable dt = new DataTable();
            dt = ds.Tables[0];

           //creating a table dynamically

            HtmlTable table = new HtmlTable();
            HtmlTableRow tr = null;
            HtmlTableCell tc = null;

          //displaying labels for displaying column names in the table

            if (dt.Columns.Count - 1 > 0)
            {
                tr = new HtmlTableRow();
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    tc = new HtmlTableCell();
                    Label lbl = new Label();
                    lbl.Text = dt.Columns[i].ColumnName;
                    lbl.ID = "lbl" + dt.Columns[i].ColumnName;
                    tc.Height = "50px";
                    tc.Width = "150px";
                    tc.Controls.Add(lbl);
                    tr.Controls.Add(tc);
                }
                table.Controls.Add(tr);

               //creating textboxes for displaying records information

                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    tr = new HtmlTableRow();
                    for (int k = 0; k < dt.Columns.Count; k++)
                    {
                        tc = new HtmlTableCell();
                        TextBox txt = new TextBox();
                        txt.ID = "txt" + j + k;
                        txt.Text = dt.Rows[j][dt.Columns[k].ToString()].ToString();
                        tc.Controls.Add(txt);
                        tr.Controls.Add(tc);
                    }
                    table.Controls.Add(tr);
                }
                form1.Controls.Add(table);
            }
        }
        catch (Exception ex)
        {
            Response.Write("Please enter a valid table");
        }
    }

thank u all.,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.