Get Values From RadGrid EditForm Controls

4 posts, 0 answers
  1. William
    William avatar
    3 posts
    Member since:
    Nov 2019

    Posted 08 Nov 2019 Link to this post

    I am trying to get the values from the RadGrid insert form and then insert those values from the form elements into a SQL database using a stored procedure. When I run the following code using the RadGrid insert command sub, empty values are inserted to the database.

    Here is the code:

    Protected Sub rg_InsertCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles rg.InsertCommand
            Dim item As GridEditFormInsertItem = CType(e.Item, GridEditFormInsertItem)
            Dim name As RadTextBox = TryCast(item.FindControl("txtName"), RadTextBox)
            Dim str As String = name.Text
        End Sub
  2. Attila Antal
    Admin
    Attila Antal avatar
    520 posts

    Posted 13 Nov 2019 Link to this post

    Hi William,

    The VB code you've showed me looks to be correct. If the RadTextBox's value is empty at this event (InsertCommand), most likely the Controls is not being bound to the template.

    Can you double check and ensure that RadTextBox's Text property is bound as shown in the following example?

    <telerik:GridTemplateColumn>
        <ItemTemplate>
            <%# Eval("SomeField") %>
        </ItemTemplate>
        <EditItemTemplate>
            <telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# Bind("SomeField") %>'></telerik:RadTextBox>
        </EditItemTemplate>
    </telerik:GridTemplateColumn>

     

    If this is done and the value is still not present at InsertCommand, please share the RadGrid markup and code behind code so that I can check out how the entire configuration looks like and advise you based on that.

     

    Kind Regards,
    Attila Antal
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. William
    William avatar
    3 posts
    Member since:
    Nov 2019

    Posted 13 Nov 2019 in reply to Attila Antal Link to this post

    Awesome! I did figure out a solution though and it works. Here is how I get the values from the edit form (using a grid template column):

    Dim insertedItem As GridEditableItem = rgRoster.MasterTableView.GetInsertItem()
            Dim name As String = CType(insertedItem("pName").FindControl("txtName"), RadTextBox).Text
            Dim rank As String = CType(insertedItem("pRank").FindControl("RadComboBox1"), RadComboBox).Text
            Dim squad As String = CType(insertedItem("pSquad").FindControl("rcSquad"), RadComboBox).Text
  4. Attila Antal
    Admin
    Attila Antal avatar
    520 posts

    Posted 14 Nov 2019 Link to this post

    Hi William,

    Yes, that is a good approach as well.

    It always depends how the Grid is structured overall, and based on that different approaches needs to be used.

    Kind regards,
    Attila Antal
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top