Hoping somebody can help me here. I am following an example posted by Telerik on how to do this in this forum. I am getting "" returned as the value for every column value (.Text). All of my grid columns are GridtTmplateColumns and the column values are labels within the template.
How do accomplish this with GridTemplateColumns? I have been struggling with this for the entire day. Can I somehow use item.findcontrol here?
Dim dtRecs As DataTable = New DataTable
For Each col As GridColumn In rgbt.Columns
If (col.ColumnType = "GridTemplateColumn") Then
Dim colstring As String
colstring = col.UniqueName
dtRecs.Columns.Add(colstring)
End If
Next
For Each item As GridDataItem In rgbt.Items
Dim newRow As DataRow = dtRecs.NewRow()
For Each column As GridColumn In rgbt.Columns
If (column.ColumnType = "GridTemplateColumn") Then
newRow(column.UniqueName) = item.(column.UniqueName).Text 'RETURNS ""
dtRecs.Rows.Add(newRow)
End If
Next
Next
Thanks!
3 Answers, 1 is accepted

here is my actual grid column:. This code is just in a function.
<telerik:GridTemplateColumn DataField="TE_SYSCODE" HeaderText="Sys Code" UniqueName="TE_SYSCODE"
SortExpression="TE_SYSCODE">
<HeaderStyle HorizontalAlign="Center" Width="67px" Wrap="False" Font-Size="Smaller" />
<ItemStyle HorizontalAlign="Right" Width="67px" Wrap="False" />
<ItemTemplate>
<asp:Label runat="server" ID="lblSyscode" CssClass="NormalNarrow" Width="63px" Text='<%#DataBinder.Eval(Container, "DataItem.TE_SYSTEMCODE") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>

I converted this to a gridboundcolumn with the same result. Except instead of "" the item.(column.UniqueName).Text value is " "
Not sure what I am doing wrong....

For what it's worth to anyone else, here is how I ended up looping through my filtered grid and copying the filtered rows into a datatable. I know it isn't pretty but it works perfectly:
Private Function getFilteredRows(ByVal formattedBatchId As String) As DataTable
Dim dtRecs As New DataTable
Dim R As DataRow
Dim addRowFlag As Boolean
For Each item As GridItem In rgbt.MasterTableView.Items
Dim lblEmpMsg As Label = CType(item.FindControl("lblEmpMsg"), Label)
Dim empMsgVal As String = lblEmpMsg.Text
Dim lblAmt As Label = CType(item.FindControl("lblExpAmount"), Label)
Dim amtVal As String = Replace(lblAmt.Text, "$", "")
Dim lblSeqNum As Label = CType(item.FindControl("lblSeqNum"), Label)
Dim seqNumVal As String = lblSeqNum.Text
Dim lblJobNum As Label = CType(item.FindControl("lblJobNum"), Label)
Dim jobNumVal As String = lblJobNum.Text
Dim lblPhase As Label = CType(item.FindControl("lblPhase"), Label)
Dim phaseVal As String = lblPhase.Text
Dim lblCategory As Label = CType(item.FindControl("lblCategory"), Label)
Dim categoryVal As String = lblCategory.Text
Dim lblVendor As Label = CType(item.FindControl("lblVendor"), Label)
Dim vendorVal As String = lblVendor.Text
Dim lblWed As Label = CType(item.FindControl("lblCurWkEndDte"), Label)
Dim wedVal As String = lblWed.Text
Dim lblInvoiceNum As Label = CType(item.FindControl("lblInvoiceNum"), Label)
Dim invoiceNumVal As String = lblInvoiceNum.Text
invoiceNumVal = Replace(invoiceNumVal, "BATCH#", "-" & formattedBatchId)
R = dtRecs.NewRow
addRowFlag = False
For Each column As GridColumn In rgbt.Columns
If (column.ColumnType = "GridTemplateColumn") Then
If (column.ColumnGroupName = "fileField") Then
Dim colstring As String = column.UniqueName
If (dtRecs.Columns.Contains(colstring) = False) Then
Dim newcolumn = New DataColumn()
newcolumn.DataType = System.Type.GetType("System.String")
newcolumn.ColumnName = colstring
dtRecs.Columns.Add(newcolumn)
'set the data table column to it's appropriate label value
If (colstring = "TE_SEQUENCE_NO") Then
R(colstring) = seqNumVal
addRowFlag = True
End If
If (colstring = "TE_JOB_NUMBER") Then
R(colstring) = jobNumVal
addRowFlag = True
End If
If (colstring = "TE_PHASE") Then
R(colstring) = phaseVal
addRowFlag = True
End If
If (colstring = "TE_CATEGORY") Then
R(colstring) = categoryVal
addRowFlag = True
End If
If (colstring = "Vendor") Then
R(colstring) = vendorVal
addRowFlag = True
End If
If (colstring = "InvoiceNum") Then
R(colstring) = invoiceNumVal
addRowFlag = True
End If
If (colstring = "emp_msg") Then
R(colstring) = empMsgVal
addRowFlag = True
End If
If (colstring = "TE_EXP_AMOUNT") Then
R(colstring) = amtVal
addRowFlag = True
End If
If (colstring = "TE_CURRENTWEEKEND_DATE") Then
R(colstring) = wedVal
addRowFlag = True
End If
Else
If (colstring = "TE_SEQUENCE_NO") Then
R(colstring) = seqNumVal
addRowFlag = True
End If
If (colstring = "TE_JOB_NUMBER") Then
R(colstring) = jobNumVal
addRowFlag = True
End If
If (colstring = "TE_PHASE") Then
R(colstring) = phaseVal
addRowFlag = True
End If
If (colstring = "TE_CATEGORY") Then
R(colstring) = categoryVal
addRowFlag = True
End If
If (colstring = "Vendor") Then
R(colstring) = vendorVal
addRowFlag = True
End If
If (colstring = "InvoiceNum") Then
R(colstring) = invoiceNumVal
addRowFlag = True
End If
If (colstring = "emp_msg") Then
R(colstring) = empMsgVal
addRowFlag = True
End If
If (colstring = "TE_EXP_AMOUNT") Then
R(colstring) = amtVal
addRowFlag = True
End If
If (colstring = "TE_CURRENTWEEKEND_DATE") Then
R(colstring) = wedVal
addRowFlag = True
End If
End If
End If
End If
Next
If (addRowFlag) Then
dtRecs.Rows.Add(R)
End If
Next
Return dtRecs
End Function