0

I am creating a runtime table which is taking values from the database, but the problem is that the all the rows of database table is showing in one column when running on browser, how to divide the data in two columns .
the code is shown below which is presenting the data in one column....

protected void Page_Load(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection("Data Source=SWATI;Initial    Catalog=jwellerydesign;Integrated Security=True");
    con.Open();
    SqlCommand com = new SqlCommand("select * from category", con);
    SqlDataReader dr = com.ExecuteReader();
    Table tb = new Table();
    while (dr.Read())
    {

        string a = dr.GetInt32(0).ToString();
        TableRow tr = new TableRow();
        ImageButton img = new ImageButton();

        TableCell td = new TableCell();

        img.ToolTip = dr.GetString(1);
        img.CommandArgument = a;
        img.Command += new CommandEventHandler(click);
        string filename = dr.GetString(2);

        img.ImageUrl = filename;
        img.ImageAlign = 0;

        td.Controls.Add(img);

        td.Height = Unit.Pixel(150);
        td.Width = Unit.Pixel(150);

        tr.Controls.Add(td);

        tb.Controls.Add(tr);
    }
    Panel1.Controls.Add(tb);
}

how to show same table data in two columns ???

Edited by Dani: Formatting fixed

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by bravo659
0

Hi maybe you like to add more columns to your output of tables. td.Controls.Add(img);

td.Height = Unit.Pixel(150);
td.Width = Unit.Pixel(150);

tr.Controls.Add(td);

tb.Controls.Add(tr);
}
Panel1.Controls.Add(tb);

I only see you're adding only one column ([img] column). You must specify how many columns you want it to display. If you created a database in sql with three columns then:
SqlCommand com = new SqlCommand("select * from category", con);
will select all the columns in the database.

0

Thanks for reply , I want to show only image from the database table but all the entries of table are showing in one column , how is it possible to show these values in two columns, if I add two columns in this code then what code I'll have to write for it and how data from table will be add half in one column and half in another column .
If you didn't understand the query please tell me how can I add the .aspx page to this thread to show you??

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.