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

Getting data from textboxs, within a radgrid

2 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 24 Oct 2012, 02:26 PM
Hi,
I have a rad grid...
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateSelectColumn="True" CellSpacing="0"
                        GridLines="Horizontal" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource"
                        AllowAutomaticUpdates="false" AllowPaging="false" AllowSorting="false" Width="100%">
                        <SortingSettings EnableSkinSortStyles="false" />
                        <MasterTableView DataKeyNames="Code" PageSize="20" Width="100%">
                            <Columns>
                                <telerik:GridTemplateColumn UniqueName="txtQTY" HeaderText="Quantity">
                                    <ItemTemplate>
                                        <asp:TextBox runat="server" ID="QTYtextbox" Width="40px" Enabled="true" Text='<%# Bind("QTY") %>'> </asp:TextBox>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn DataField="Code" HeaderText="Code" UniqueName="Code" FilterControlAltText="Filter Code column"
                                    SortExpression="Code" ItemStyle-Width="50px">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name" FilterControlAltText="Filter Name column"
                                    SortExpression="Name" ItemStyle-Width="200px">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Units" HeaderText="Units" UniqueName="Units"
                                    FilterControlAltText="Filter Units column" SortExpression="Units" ItemStyle-Width="25px">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="QTY" HeaderText="QTY" UniqueName="colQTY" Visible="True"
                                    ItemStyle-Width="25px">
                                </telerik:GridBoundColumn>
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>

It is populated using data binding and all the columns show data...
Protected Sub RadGrid1_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
    'Loads Data into the table
    Dim ordlist As New dbrcOrdEst(Session("ConnectionString"))
    Dim dt As DataTable = ordlist.ListOrderEstimates(498)
    RadGrid1.DataSource = dt
End Sub

However what I want to do is take my textbox column, and return the values back into the database, however I can't get data out of the Textboxes, I know how to manipulate the data once I've got it, but I can't get it. This code does what I want on standard columns but not on textbox columns what am I missing 
Protected Sub btnImport_Click(sender As Object, e As System.EventArgs) Handles btnImport.Click
    For Each item As GridDataItem In RadGrid1.Items
        Dim value As String
        value = item.Cells(2).Text
'DB Functionality
    Next
End Sub

Thanks in advance for your help, Ryan 

2 Answers, 1 is accepted

Sort by
0
Accepted
Casey
Top achievements
Rank 1
answered on 24 Oct 2012, 03:20 PM
Hi Ryan,

You would just need to modify your click event to find the TextBox control instead of using the text property of the GridDataItem.

I'm used to coding in C#, not VB, so hopefully I wrote it correctly.

Hope this helps!
Casey

Protected Sub btnImport_Click(sender As Object, e As System.EventArgs) Handles btnImport.Click
    For Each item As GridDataItem In RadGrid1.Items
        Dim value As String
        YourTextBox = TryCast(item.FindControl("QTYtextbox"), TextBox)
        value = YourTextBox.Text
    'DB Functionality
    Next
End Sub
0
Accepted
Tsvetoslav
Telerik team
answered on 26 Oct 2012, 05:46 AM
Hi Ryan,

An alternative approach is to add the Qty field to the MasterTableView's DataKeyNames collection and use the GridDataItem's GetDataKeyValue(....) method to obtain the value required:

Protected Sub btnImport_Click(sender As Object, e As System.EventArgs) Handles btnImport.Click
  
    For Each item As GridDataItem In RadGrid1.Items
  
        Dim value As String
  
        value = item.GetDataKeyValue("Qty").ToString()
    'DB Functionality
  
    Next
  
End Sub



All the best,
Tsvetoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Casey
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or