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

How to add several rows to grid in code-behind

4 Answers 241 Views
Grid
This is a migrated thread and some comments may be shown as answers.
blablabla
Top achievements
Rank 1
blablabla asked on 29 Nov 2011, 01:54 PM
Hi,

I need to be able to add several rows to a RadGrid when I click on the Add button I have defined in the CommandItemTemplate.

The radgrid is using InPlace editing. The template has an "Add" button and a textbox next to it that specifies the number of rows to add.

So let's say I specified 5 in the textbox, I clicked on the Add button, and the ItemCommand or ButtonClick events are fired. How can I add 5 rows to the grid in my code-behind?

I tried to catch the Command in the ItemCommand event and then calling MyGrid.MasterTableView.InserItem() inside a for loop, but it doesn't work.

Thank you.

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Nov 2011, 01:58 PM
Hello,

Check the following demo which implements the same.
Grid / Command Item

-Shinu.
0
blablabla
Top achievements
Rank 1
answered on 29 Nov 2011, 03:37 PM
Thanks for the reply Shinu, but I don't see how that example implements what I'm asking.

I already have something similar. I want to be able to add several rows at once when I click the button "Add Record", but I haven't figured out how yet.
0
blablabla
Top achievements
Rank 1
answered on 29 Nov 2011, 05:41 PM
I ended up adding empty rows to the "datasource" then rebinding the grid. I put datasource in quotes because I was binding to a list of entity objects and now I'm binding to a union of a list of entity objects saved in session and the result from the database.
0
Enoch
Top achievements
Rank 1
answered on 27 Mar 2012, 10:03 AM

          
           DataTable table = new DataTable();

            DataColumn column1 = new DataColumn();
            column1.DataType = Type.GetType("System.String");
            column1.AllowDBNull = true;
            column1.Caption = "test";
            column1.ColumnName = "ITEM";

            table.Columns.Add(column1);
            DataRow rw = table.NewRow();
            rw["ITEM"] = "1";
          
            table.Rows.Add(rw);
            DataSet ds = new DataSet();
           
            ds.Tables.Add(table);
            this.ctrGrdSerchPKG.DataSource = ds;
            this.ctrGrdSerchPKG.DataBind();

            oen111@naver.com

Tags
Grid
Asked by
blablabla
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
blablabla
Top achievements
Rank 1
Enoch
Top achievements
Rank 1
Share this question
or