RadGrid Row Creation programmatically

8 posts, 0 answers
  1. Liji Jose
    Liji Jose avatar
    52 posts
    Member since:
    Jan 2010

    Posted 09 Feb 2010 Link to this post

    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......
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 09 Feb 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Liji Jose
    Liji Jose avatar
    52 posts
    Member since:
    Jan 2010

    Posted 09 Feb 2010 Link to this post

    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....

  5. Martin
    Admin
    Martin avatar
    811 posts

    Posted 11 Feb 2010 Link to this post

    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.
  6. Neerav
    Neerav avatar
    50 posts
    Member since:
    Nov 2010

    Posted 25 Nov 2010 Link to this post

    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
  7. Prangadj
    Prangadj avatar
    174 posts
    Member since:
    Jan 2008

    Posted 25 Nov 2010 Link to this post

    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
  8. Rohit
    Rohit avatar
    13 posts
    Member since:
    Aug 2010

    Posted 26 Nov 2010 Link to this post

    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
  9. Neerav
    Neerav avatar
    50 posts
    Member since:
    Nov 2010

    Posted 29 Nov 2010 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017