Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

This is my code..

Here showing only one row. How to increase another one row or multiple rows in gridview.
C#
DataTable dt = new DataTable();
        dt.Columns.Add("OrderNo");
        dt.Columns.Add("gvQbvNo");
        dt.Columns.Add("gvItemDesc");


        DataRow dr = dt.NewRow();
        
        dr["orderno"] = 1;
        dr["gvQbvNo"] = "100";
        dr["gvItemDesc"] = "maya";
        dt.Rows.Add(dr);
        dt.AcceptChanges();

        GridView1.DataSource = dt;
        GridView1.DataBind();
Posted
Updated 5-Oct-13 1:08am
v2
Comments
abbaspirmoradi 5-Oct-13 7:11am    
what is your mean?
Member 10222278 5-Oct-13 7:17am    
How to increase multiple Rows in Gridview?
Member 10222278 5-Oct-13 7:19am    
I have using my gridview in Textbox,label and dropdownlist
So i was get value in another one aspx form.

So i want increase next rows but showing same row only one value assigned.

Please solve this problem..
Azee 5-Oct-13 13:21pm    
Hey there, Do you mean, you are redirecting to another page, multiple times an each time adding a row, but losing the previous ones?

1 solution

C#
protected void Page_Load(object sender, EventArgs e)
   {
    if(!IsPostBack)
    {
      BindGridviewData();
    }
   }
/// <summary>
/// Dynamically create & bind data to datatable and bind datatable to gridview
/// </summary>
    protected void BindGridviewData()
    {
     DataTable dt = new DataTable();
      dt.Columns.Add("UserId", typeof(Int32));
     dt.Columns.Add("UserName", typeof (string));
     dt.Columns.Add("Education", typeof (string));
     dt.Columns.Add("Location",typeof(string));

     DataRow dtrow = dt.NewRow();    // Create New Row
     dtrow["UserId"] = 1;            //Bind Data to Columns
     dtrow["UserName"] = "ramesh";
     dtrow["Education"] = "B.Tech";
     dtrow["Location"] = "Chennai";
     dt.Rows.Add(dtrow);

     dtrow = dt.NewRow();               // Create New Row
     dtrow["UserId"] = 2;               //Bind Data to Columns
     dtrow["UserName"] = "srinu";
     dtrow["Education"] = "MBA";
     dtrow["Location"] = "Nagpur";
     dt.Rows.Add(dtrow);

     dtrow = dt.NewRow();              // Create New Row
      dtrow["UserId"] = 3;              //Bind Data to Columns
dtrow["UserName"] = "Sambasiva";
dtrow["Education"] = "B.Tech";
dtrow["Location"] = "Nuzividu";
dt.Rows.Add(dtrow);

dtrow = dt.NewRow();              // Create New Row
dtrow["UserId"] = 4;              //Bind Data to Columns
dtrow["UserName"] = "Ramu";
dtrow["Education"] = "CA";
dtrow["Location"] = "Guntur";
dt.Rows.Add(dtrow);
gvDetails.DataSource = dt;
gvDetails.DataBind();
}
 
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