dynamic table

create a dynamic table

Page 1 of 1

5 Replies - 2316 Views - Last Post: 10 August 2010 - 09:55 AM Rate Topic: -----

#1 thevest12000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-August 10

dynamic table

Posted 09 August 2010 - 12:19 PM

how to create a dynamic table in a .net environnement
i use sql server for my databases
thanks
Is This A Good Question/Topic? 0
  • +

Replies To: dynamic table

#2 danny_kay1710  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 28
  • View blog
  • Posts: 358
  • Joined: 27-April 08

Re: dynamic table

Posted 09 August 2010 - 12:21 PM

You should really try before posting on a forum. The rules do ask for a best effort.

http://lmgtfy.com/?q...et+datagridview
Was This Post Helpful? 0
  • +
  • -

#3 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: dynamic table

Posted 09 August 2010 - 01:56 PM

@danny_kay1710 do you realize that DIC is likely to pop up in a google search? So, not only is lmgtfy a slap in the face but there is a possibility for a continuous loop leading right back here. You should really refrain from using it. Don't be so mean to newbies!


Anyways, @thevest12000 this is a pretty novice question to ask.
It would be easier to help you if you showed us what you have tried so far to create your table because there are several ways to create it....

Whenever I have a question regarding something .NET related I first refer to the MSDN Library. This library contains documentation about all .NET controls, concepts, patterns/practices and more. It's a great place to start when you don't know about something. There you will find documentation about the SqlConnection class which lets you connect to a database, and the DataAdapter class which uses a SqlConnection to "Fill" a DataSet with populated DataTables!

There's a lot of information there. After you've gone through the links I've posted ...could you please post back with details on what exactly are you having difficulties with?

-Frinny

This post has been edited by Frinavale: 10 August 2010 - 05:55 AM

Was This Post Helpful? 0
  • +
  • -

#4 ans2007kumar  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 25-September 09

Re: dynamic table

Posted 10 August 2010 - 02:52 AM

Here is an example how to create dynamic table
protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            string d1 = RadComboBox1.SelectedValue.ToString();
            string s = RadComboBox2.SelectedValue.ToString();
            if (d1 != "Select" || s != "Select")
            {
                SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\afset.mdf;Integrated Security=True;User Instance=True");
                SqlCommand c = new SqlCommand("select book,summary,date_added,bookname from profile WHERE Dept=@d1 AND sem=@s", con);
                con.Open();
                SqlDataReader dr = c.ExecuteReader();


                if (dr.Read())
                {

                    int er = 1;
                    for (int i = 0; i < er; i++)
                    {
                        TableRow tr = new TableRow();
                        {
                            TableCell tc = new TableCell();
                            {
                                Label l = new Label();
                                l.Text = dr["bookname"].ToString();
                                l.Font.Bold = true;
                                tc.Controls.Add(l);
                                tc.Width = 360;
                            }
                            tc.BackColor = ColorTranslator.FromHtml("#0099FF");
                            tr.Cells.Add(tc);
                            TableCell t2 = new TableCell();
                            {
                                Label lb = new Label();
                                lb.Text = dr["date_added"].ToString() + " " + "\n";
                                t2.Controls.Add(lb);

                            }
                            t2.BackColor = ColorTranslator.FromHtml("#0099FF");
                            t2.Width = 60;
                            tr.Cells.Add(t2);
                        }
                        TableRow tr2 = new TableRow();
                        {
                            TableCell t3 = new TableCell();
                            {
                                Label lb1 = new Label();
                                lb1.Text = dr["summary"].ToString();
                                t3.Controls.Add(lb1);
                                LinkButton l = new LinkButton();
                                l.PostBackUrl = dr["Book"].ToString();
                                l.Text = "Download";
                                t3.Controls.Add(l);
                            }
                            t3.BackColor = Color.Wheat;                            
                            t3.ColumnSpan=2;
                            tr.Cells.Add(t3);
                        }
                    
                        TableRow tr3 = new TableRow();
                        {
                            TableCell tc = new TableCell();
                            {}
                            tc.ColumnSpan = 2;
                            tc.Height=10;
                        }
                        Table1.Rows.Add(tr);
                        Table1.Rows.Add(tr2);
                    }
                }
                con.Close();
            }
        }
        catch (Exception ex)
                {
                    HttpCookie m = new HttpCookie("exe");
                    m.Values["e"] = ex.StackTrace.ToString();
                    Response.Cookies.Add(m);
                    Response.Redirect("~\\Error.aspx");
                }            
    }

I hope it help you mark it if yes

you can create table like

Table table1 = new Table();
if you want but i say use table control to place where you want it is good for alignment.
Was This Post Helpful? 0
  • +
  • -

#5 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: dynamic table

Posted 10 August 2010 - 08:38 AM

Also, you may wish to look into Repeaters, they are godly!
Was This Post Helpful? 0
  • +
  • -

#6 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: dynamic table

Posted 10 August 2010 - 09:55 AM

@Imdsm: you can use a Repeater to specify how DataTable's data is displayed to the end-user so that the user can interact with the data. They can be bound to a DataTable or any other collection of data. Repeaters don't really have anything to do with dynamically creating a DataTable...

-Frinny

This post has been edited by Frinavale: 10 August 2010 - 09:55 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1