Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
How can I generate automatic new rows inside grid view.
I am using a button for display first row for grid how can I generate next row after first row.

My code is

C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        create_datatable();
    }
}
private void create_datatable()
{
    dr = new TableRow();
    dt.Columns.Add("Product_Name");
    dt.Columns.Add("Product_Rate");
    dt.Columns.Add("Product_Quantity");
    dt.Columns.Add("Product_Amount");
    Session["Address"] = dt;
    radGrid1.DataSource = dt;
    radGrid1.DataBind();
}



C#
protected void btn1_click(object sender, EventArgs e)
{
    dt = (DataTable)Session["Address"];
    if (dt.Rows.Count != 0)
    {
        if (dt.Columns.Count != 0)
        {
            create_datatable();
        }
    }
    DataRow dr = dt.NewRow();

    dt.Rows.Add(dr);
    radGrid1.DataSource = dt;
    radGrid1.Rebind();
}


[edit]Tags, subject, formatting, capitals - OriginalGriff[/edit]
Posted
Updated 3-Nov-10 0:13am
v2

1 solution

Hi
add following lines of code:

C#
//Define global variable
dt = (DataTable)Session["Address"];

protected void btn1_click(object sender, EventArgs e)
        {
            
            if (dt.Rows.Count != 0)
            {
                if (dt.Columns.Count != 0)
                {
                    create_datatable();
                }
                else
                {
                    create_datatable_row();
                }
            }
            
            radGrid1.DataSource = dt;
            radGrid1.Rebind();
        }
     private void create_datatable_row()
     {
        DataRow dr = dt.NewRow();
        dt.Rows.Add(dr);
     }



Please do let me know, if you have any doubt.

Please provide "Vote":thumbsup: if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen
 
Share this answer
 
Comments
Dalek Dave 3-Nov-10 6:22am    
Good Answer.
Pawan Kiran 3-Nov-10 6:56am    
Don't mine for Deleted the Comment, Accidentally it happend.
call to .net 3-Nov-10 7:00am    
I am using yr code but when i define
dt =(DataTable)Session["Address"];
showing error and if i am using inside and debug with yr code debug program then if (dt.Rows.Count != 0) after this row directly come to radGrid1.DataSource = dt; and no row is creating

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