This is a migrated thread and some comments may be shown as answers.

Dynamically rows add to radgrid

1 Answer 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yogish
Top achievements
Rank 1
Yogish asked on 09 Jan 2012, 07:20 AM
How to dynamically add rows to radgrid when press add new button . in my case when i press add  new button in the first time it works fine and it add one row. but after that when i press it wont effect..

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Jul 2012, 10:01 AM
Hi,

Here is the sample code i tried to add rows dynamically on clicking of "Add New Record".

C#:
public static int count = 0;
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    DataTable ds = new DataTable();
    RadGrid1.DataSource = addBlankLines(ds, count);
 
}
private DataTable addBlankLines(DataTable ds, int count)
{
    if (count != 0)
    {
        DataRow drBlank = default(DataRow);
 
        for (int i = 0; i < count; i++)
        {
 
            drBlank = ds.NewRow();
            ds.Rows.Add(drBlank);
 
 
        }
    }
    return ds;
}
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.InitInsertCommandName)
    {
        e.Canceled = true;
        count = count + 1;
        RadGrid1.Rebind();
    }
}

Thanks,
Shinu.
Tags
Grid
Asked by
Yogish
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or