Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Button6_Click(object sender, EventArgs e)
    {
      {
            DataTable dt = new DataTable();
            DataRow dr = dt.NewRow();
            DataColumn dc = dt.Columns.Add("id", typeof(int));
            dt.Columns["id"].AutoIncrement = true;
            dt.Columns["id"].AutoIncrementSeed = 1;
            DataColumn[] pk = new DataColumn[1];
            pk[0] = dt.Columns["id"];
            dt.PrimaryKey = pk;
            dc.AutoIncrementSeed = 1;
            dc.AutoIncrementStep = 1;
            dt.Columns.Add(new System.Data.DataColumn("price", typeof(String)));
            dt.Columns.Add(new System.Data.DataColumn("quantity", typeof(String)));
            dt.Columns.Add(new System.Data.DataColumn("item", typeof(String)));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dr = dt.NewRow();
                dr[1] = Label5.Text;
                dr[2] = TextBox1.Text + TextBox2.Text;
                dr[3] = this.Session["variable2"];
                dt.Rows.Add(dr);
            }
            GridView1.DataSource = dt;
            GridView1.DataBind();
            GridView1.Visible = true;
        }
     }
Posted
Updated 4-Nov-14 17:09pm
v2
Comments
Laiju k 4-Nov-14 23:26pm    
can you post the source code

1 solution

first .. this

C#
dr = dt.NewRow();
                dr[1] = Label5.Text;
                dr[2] = TextBox1.Text + TextBox2.Text;
                dr[3] = this.Session["variable2"];


surely would be 'nicer' as

C#
dr = dt.NewRow();
                dr["price"] = Label5.Text;
                dr["quantity"] = TextBox1.Text + TextBox2.Text;
                dr["item"] = this.Session["variable2"];


second .. Im not so sure about this

GridView1.DataBind();


wouldn't that need to be

GridView1.Refresh();


?
 
Share this answer
 
Comments
samip rot 5-Nov-14 1:31am    
i m using visual studio 2010 so no definition for refresh

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