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

[Solved] Manually Accessing Grid Data

2 Answers 151 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Edward
Top achievements
Rank 1
Edward asked on 28 Jul 2009, 07:19 PM
We currently have a need to have a radgrid with a data source pulling the data, but then we need to allow people to post data into three columns without having them update until they are done.  The grid view code is below. Is there a way to go row by row, and get the data for each of the text boxes we created?  Once they have entered the fields they are wanting to update, they will press a button which would go thru each row and check to see if they entered payment data.

<

 

telerik:RadGrid ID="Grid_PaymentPosting" runat="server" AutoGenerateColumns="False"

 

 

DataSourceID="SQLBalances" Skin="Vista" AllowSorting="True">

 

 

<MasterTableView DataKeyNames="FamilyID" DataSourceID="SQLBalances">

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</ExpandCollapseColumn>

 

 

<Columns>

 

 

<telerik:GridBoundColumn DataField="FamilyID" DataType="System.Int32"

 

 

HeaderText="FamilyID" ReadOnly="True" SortExpression="FamilyID"

 

 

UniqueName="FamilyID" Visible="False">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="UserID" DataType="System.Int32"

 

 

HeaderText="UserID" SortExpression="UserID" UniqueName="UserID" Visible="False">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="SystemFamilyID" DataType="System.Int32"

 

 

HeaderText="SystemFamilyID" SortExpression="SystemFamilyID"

 

 

UniqueName="SystemFamilyID" Visible="False">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="FamilyName" HeaderText="FamilyName"

 

 

SortExpression="FamilyName" UniqueName="FamilyName">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="ParentFirstName"

 

 

HeaderText="ParentFirstName" SortExpression="ParentFirstName"

 

 

UniqueName="ParentFirstName">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="ParentLastName" HeaderText="ParentLastName"

 

 

SortExpression="ParentLastName" UniqueName="ParentLastName">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="RegFees" DataType="System.Decimal"

 

 

EmptyDataText="0.00" HeaderText="Registration Fees" ReadOnly="True"

 

 

SortExpression="RegFees" UniqueName="RegFees">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Payments" DataType="System.Decimal"

 

 

EmptyDataText="0.00" HeaderText="Payments" ReadOnly="True"

 

 

SortExpression="Payments" UniqueName="Payments">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="OrganizationID" DataType="System.Int32"

 

 

HeaderText="OrganizationID" SortExpression="OrganizationID"

 

 

UniqueName="OrganizationID" Visible="False">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridTemplateColumn HeaderText="Name On Check"

 

 

UniqueName="NameOnCheck">

 

 

<ItemTemplate>

 

 

<telerik:RadTextBox ID="TxtNameOnCheck" Runat="server"

 

 

EmptyMessage="Enter Name On Check" Skin="Sunset" Width="200px">

 

 

</telerik:RadTextBox>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn HeaderText="Check Number"

 

 

UniqueName="CheckNumber">

 

 

<ItemTemplate>

 

 

<telerik:RadTextBox ID="TxtCheckNumber" Runat="server"

 

 

EmptyMessage="Check Number" Skin="Sunset" Width="125px">

 

 

</telerik:RadTextBox>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn HeaderText="Check Amount"

 

 

UniqueName="CheckAmount">

 

 

<ItemTemplate>

 

 

<telerik:RadNumericTextBox ID="TxtAmount" Runat="server"

 

 

Culture="English (United States)" Skin="Hay" Type="Currency" Value="0"

 

 

Width="45px">

 

 

</telerik:RadNumericTextBox>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

</Columns>

 

 

</MasterTableView>

 

 

<ClientSettings>

 

 

<Selecting AllowRowSelect="True" />

 

 

</ClientSettings>

 

 

</telerik:RadGrid>

 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Jul 2009, 05:02 AM
Hello Edward,

You can try out the following code to loop through the item collection of your grid and update changes on clicking a button:
c#:
protected void Button1_Click(object sender, EventArgs e) 
    { 
         foreach (GridDataItem item in Grid_PaymentPosting.Items) 
           { 
               string strtxt1 = ((RadTextBox)item.FindControl("TxtNameOnCheck")).Text; 
               string strtxt2 = ((RadTextBox)item.FindControl("TxtCheckNumber")).Text; 
               string strtxt3 = ((RadNumericTextBox)item.FindControl("TxtAmount")).Text; 
 
              // update query   
            
              // SQLBalances.UpdateCommand = String.Format("Update TableName SET ColumnName='{0}' WHERE CustomerID='{1}'", strtxt1, editedItem.GetDataKeyValue("keyfield").ToString()); 
              // SQLBalances.Update();                
               
           }   
        Grid_PaymentPosting.Rebind();        
    } 

Thanks
Princy.
0
Michael Coffey Jr
Top achievements
Rank 1
answered on 29 Jul 2009, 01:44 PM
Thanks for your reply, if anyone is looking for the version is VB here it is:

Dim

 

MainItems As GridDataItem

 

 

Dim TxtNameOnCheck As String

 

 

Dim TxtCheckNumber As String

 

 

Dim TxtCheckAmount As String

 

 

For Each MainItems In Grid_PaymentPosting.Items

 

TxtNameOnCheck =

CType(MainItems.FindControl("TxtNameOnCheck"), RadTextBox).Text

 

TxtCheckNumber =

CType(MainItems.FindControl("TxtCheckNumber"), RadTextBox).Text

 

TxtCheckAmount =

CType(MainItems.FindControl("TxtAmount"), RadNumericTextBox).Text

 

 

Next

 

Tags
Grid
Asked by
Edward
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Michael Coffey Jr
Top achievements
Rank 1
Share this question
or