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

RadGrid Row Creation programmatically

7 Answers 2056 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Liji Jose
Top achievements
Rank 1
Liji Jose asked on 09 Feb 2010, 10:14 AM
How can I create a RadGrid row programmatically?

I need to loop through the existing rows in the Radgrid and add a new row on a button click, ie., based on the number of existing rows a new row needs to be added.

or is there any way to get the ROWCount at the server-side?

Please guide me......

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Feb 2010, 10:28 AM
Hello

It is not poassible to directly add a row to radgrid dynamically, but what you can do is manipulate it using datatable .You can add rows  to DataTable and set it as grid DataSource. There is an example shown in the following forum on how to add row dynamically. I hope this will help you to get started.

Dynamically add new rows to radgrid

-Shinu.
0
Liji Jose
Top achievements
Rank 1
answered on 09 Feb 2010, 11:39 AM

Thanks Shinu for ur reply...

But what I  need is to loop through the existing rows in the Grid and add a new row accordingly.

The scenario is ,

I have a Grid with an ADD button, when the user clicks the button, a new row gets added in the Grid, if the user clicks it for the second time, one more row gets added and it goes on.
At the server-side I'll create the GridBound column controls(like ComboBox, TextBox) and loop through the number of existing rows in the Grid and add a new row to the DataTable. This datatable I'm binding to the Grid. So here how can I get the RowCount of radGrid so that I can add rows as many times as needed.

Code Snippet:

    Private Sub FilterAddRow()
      

 

        Dim

 

m_objDTFilter As New DataTable

 

 

       Dim l_intRowCount As Integer

 

 

       Dim l_objDDLColumnName As RadComboBox = CType(gvFilter.FindControl("ddlColumn"), RadComboBox)

 

 

    Dim l_objDDLOperator As RadComboBox = CType(gvFilter.FindControl("ddlOperator"), RadComboBox)

 

 

    Dim l_objDDLLogical As RadComboBox = CType(gvFilter.FindControl("ddlLogical"), RadComboBox)

 

 

    Dim l_objTxtValue As RadTextBox = CType(gvFilter.FindControl("txtValue"), RadTextBox)

 

 

    For l_intRowCount = 0 To (RadGridRowCount)
        m_objDTFilter.Rows.Add(

New Object() {l_objDDLColumnName, l_objDDLOperator, l_objTxtValue, l_objDDLLogical})

 

 

    Next

 

 

 

 

m_objDTFilter.Rows.Add()

 

Me.cmdDelete.Enabled = True

 

 

 

gvFilter.DataSource = m_objDTFilter

 

gvFilter.DataBind()

 

Please give me an idea....

0
Martin
Telerik team
answered on 11 Feb 2010, 08:14 PM
Hello Liji Jose,

As Shinu stated it is not possible to directly add or remove items from the RadGrid. As a databound control it is designed to visualize the records from a data source control. Therefore to alter the RadGrid items you would need to alter the records from the source control it uses.

For your reference I have attached a small sample project demonstrating how to add new items programatically.

I hope this helps,
Martin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Neerav
Top achievements
Rank 1
answered on 25 Nov 2010, 03:14 PM
I want to add rows to radgrid programatically using columns and template columns already defined in design(.aspx) page.
Using datatable as datasource will require adding columns to it. I don't want to create new columns. Can datatable defined in code behind use existing column id(both column and template column).

Kindly reply
0
Prangadj
Top achievements
Rank 1
answered on 25 Nov 2010, 06:34 PM
The telerick ajax grid rows can only be bound, dear. Programming creation is supported as told in the docs here:
http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html

Prangadj
0
Rohit
Top achievements
Rank 1
answered on 26 Nov 2010, 09:14 AM
Hello Prangadj,
Thanks for your reply.

I have a empty radgrid namely "radgrid1" defined in aspx page. I have another filled radgrid namely "radgrid2" in radwindow on same
page. "radgrid2" has a "template column" which on click will delete a row from "radgrid2" and add it to "radgrid1". "radgrid1" as i said earlier is an empty grid which will get filled with row deleted from "radgrid2". But again, "radgrid1" should again have three columns including one "template column" which again on click will delete a row from "radgrid1".
I have defined my "radgrid1" in aspx page which ofcourse is not bound to any database since it will contain rows from "radgrid2".
I am trying to do is, i want to add rows dynamically from "radgrid2" to "radgrid1" where radgrid1 will have three columns including one "template column".

Now My question is, considering the above scenario, should I create columns(including "template column") in .aspx page or create them from code behind using datatabel.columns.add() method.

If I create columns in .aspx page including "template column" how can i use these columns id's in code behind to add rows.

If I use datatabel.columns.add() method, then I am not able to create a "template column".

Kindly reply.
Thanks
0
Neerav
Top achievements
Rank 1
answered on 29 Nov 2010, 04:23 PM
Hello every one,
I have two radgrids radgrid1 and radgrid2. Radgrid1 is empty. Radgrid2 is filled with data. I have created a template column in radgrid2 which on click,  will move the row from radgrid2 to radgrid1.After moving, the row should also get deleted from radgrid2. I have bounded columns of radgrid2 in .aspx page with sqlserver database.
My code behind is able to move data from radgrid2 to radgrid1 but I am not getting the row to be deleted from radgrid2. This data should get deleted temprorarily since whenever the radgrid2 gets opens it should displays all rows(including rows moved from radgrid2 to radgrid1).
I know that telerik:gridclientdelete column deletes rows from client side. But the problem is I want to achieve both moving an deleting from same template column.
Can anyone let me know as to how to create a template column which move ane delete row from client side only.

Kinldy reply.

Thanks and regards
Tags
Grid
Asked by
Liji Jose
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Liji Jose
Top achievements
Rank 1
Martin
Telerik team
Neerav
Top achievements
Rank 1
Prangadj
Top achievements
Rank 1
Rohit
Top achievements
Rank 1
Share this question
or