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

Get Values From RadGrid EditForm Controls

3 Answers 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 08 Nov 2019, 07:57 PM

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

3 Answers, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 13 Nov 2019, 03:46 PM

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.
0
William
Top achievements
Rank 1
answered on 14 Nov 2019, 12:44 AM
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
0
Attila Antal
Telerik team
answered on 14 Nov 2019, 08:53 PM

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.
Tags
Grid
Asked by
William
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
William
Top achievements
Rank 1
Share this question
or