Telerik ASP.NET - Iterate through a grid

This code example will show how to iterate through an ASP.NET Telerik grid, and we'll show how to access different column types. 

Specifically, we'll look at templated columns, datakeyvalues, and bound columns

 

 

 

The grid:

<telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="False" CssClass="grid" AllowPaging="False" Width="800px" >
    <MasterTableView DataKeyNames="sopnumbe, soptype, custnmbr" >
        <Columns>
            <telerik:GridTemplateColumn HeaderStyle-Width="50px" UniqueName="Selected" HeaderText="Select">
                <ItemTemplate>
                    <telerik:RadCheckBox runat="server" AutoPostBack="false" ID="chkSelected" ></telerik:RadCheckBox>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
 
            <telerik:GridDateTimeColumn DataField="reqshipdate" DataFormatString="{0:MM/dd/yyyy}" HeaderText="Req Ship Dt"></telerik:GridDateTimeColumn>
            <telerik:GridBoundColumn HeaderText="Order" DataField="sopnumbe" ></telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Code behind:

Note that in the markup above, we gave the templated column a 'uniquename', that value is used below

Dim bSelected As Boolean
Dim strSopnumber As String
Dim intSoptype As Int16
 
For Each item As GridDataItem In RadGrid2.Items
    Dim chkSelected As RadCheckBox = CType(item("Selected").FindControl("chkSelected"), RadCheckBox)
    bSelected = chkSelected.Checked
 
    If bSelected Then
        'get a reference to a bound column and a keyvalue
        strSopnumber = item("sopnumbe").Text
        intSoptype = item.GetDataKeyValue("soptype")
 
        'do something here
    End If
Next

 

 

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences