I am trying to take a RadGrid results with a GridClientSelectColumn and a Button that when clicked Loops through the selected records and then pulls the ID so that I can run a routine on the record (Actually plan to copy it to another table)
I can't for the life of me figure out what I am doing wrong. I get a Null Exception error anytime I try to get and assign the variable the Value of the ID field.
I am a little rusty with VB/.Net so any help would be appreciated.... if we can figure this out the next thing will be opening up the database source and copying the data from the loop through to the other table!
ASPX page
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowMultiRowSelection
=
"True"
AllowFilteringByColumn
=
"True"
AllowPaging
=
"True"
AllowSorting
=
"True"
AutoGenerateColumns
=
"False"
DataSourceID
=
"SqlDataSource1"
OnItemCommand
=
"RadGrid1_ItemCommand"
OnPreRender
=
"RadGrid1_PreRender"
PageSize
=
"100"
Skin
=
"Metro"
>
<
exportsettings
hidestructurecolumns
=
"true"
>
</
exportsettings
>
<
clientsettings
>
<
Selecting
AllowRowSelect
=
"True"
/>
</
clientsettings
>
<
mastertableview
datakeynames
=
"ID"
width
=
"100%"
>
<
PagerStyle
Mode
=
"NextPrevNumericAndAdvanced"
/>
<
Columns
>
<
telerik:GridClientSelectColumn
UniqueName
=
"ClientSelectColumn"
>
</
telerik:GridClientSelectColumn
>
<
telerik:GridBoundColumn
DataField
=
"ID"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter ID column"
HeaderText
=
"ID"
ReadOnly
=
"True"
SortExpression
=
"ID"
UniqueName
=
"ID"
>
<
columnvalidationsettings
>
<
ModelErrorMessage
Text
=
""
/>
</
columnvalidationsettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ContactServiceID"
FilterControlAltText
=
"Filter ContactServiceID column"
HeaderText
=
"ContactServiceID"
SortExpression
=
"ContactServiceID"
UniqueName
=
"ContactServiceID"
DataType
=
"System.Int32"
>
<
columnvalidationsettings
>
<
ModelErrorMessage
Text
=
""
/>
</
columnvalidationsettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"CategoryName"
FilterControlAltText
=
"Filter CategoryName column"
HeaderText
=
"CategoryName"
SortExpression
=
"CategoryName"
UniqueName
=
"CategoryName"
>
<
columnvalidationsettings
>
<
ModelErrorMessage
Text
=
""
/>
</
columnvalidationsettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"DateCreated"
FilterControlAltText
=
"Filter DateCreated column"
HeaderText
=
"DateCreated"
SortExpression
=
"DateCreated"
UniqueName
=
"DateCreated"
DataType
=
"System.DateTime"
>
<
columnvalidationsettings
>
<
ModelErrorMessage
Text
=
""
/>
</
columnvalidationsettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"DateDeleted"
FilterControlAltText
=
"Filter DateDeleted column"
HeaderText
=
"DateDeleted"
SortExpression
=
"DateDeleted"
UniqueName
=
"DateDeleted"
DataType
=
"System.DateTime"
>
<
columnvalidationsettings
>
<
ModelErrorMessage
Text
=
""
/>
</
columnvalidationsettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"UserCreated"
FilterControlAltText
=
"Filter UserCreated column"
HeaderText
=
"UserCreated"
SortExpression
=
"UserCreated"
UniqueName
=
"UserCreated"
>
<
columnvalidationsettings
>
<
ModelErrorMessage
Text
=
""
/>
</
columnvalidationsettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"UserDeleted"
FilterControlAltText
=
"Filter UserDeleted column"
HeaderText
=
"UserDeleted"
SortExpression
=
"UserDeleted"
UniqueName
=
"UserDeleted"
>
<
columnvalidationsettings
>
<
ModelErrorMessage
Text
=
""
/>
</
columnvalidationsettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"FirstName"
FilterControlAltText
=
"Filter FirstName column"
HeaderText
=
"FirstName"
SortExpression
=
"FirstName"
UniqueName
=
"FirstName"
>
<
columnvalidationsettings
>
<
ModelErrorMessage
Text
=
""
/>
</
columnvalidationsettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"LastName"
FilterControlAltText
=
"Filter LastName column"
HeaderText
=
"LastName"
SortExpression
=
"LastName"
UniqueName
=
"LastName"
>
<
columnvalidationsettings
>
<
ModelErrorMessage
Text
=
""
/>
</
columnvalidationsettings
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
ItemStyle
BackColor
=
"#DFDFDF"
/>
<
HeaderStyle
BackColor
=
"#FFFFFF"
ForeColor
=
"#767676"
/>
<
AlternatingItemStyle
BackColor
=
"#FFFFFF"
/>
</
mastertableview
>
<
ClientSettings
EnableRowHoverStyle
=
"true"
>
<
Selecting
AllowRowSelect
=
"True"
></
Selecting
>
</
ClientSettings
>
</
telerik:RadGrid
>
Code behind: **** Note I have Remarked out all of my attempted tries. I know for a fact the ID is NOT null and is an integer.
Protected
Sub
BTNrestore_Click(sender
As
Object
, e
As
EventArgs)
Handles
BTNrestore.Click
' If IDs = String.Empty Then
' IDs = CType(dataItem.FindControl("Id"), TextBox).Text
'
IDs = IDs & "," & CType(dataItem.FindControl("Id"), TextBox).Text
Dim
strAmount
As
String
For
Each
item
As
GridDataItem
In
RadGrid1.SelectedItems
' Dim lblID As Integer = CType(CType(item.FindControl("ID"), Label).Text, Integer)
' Dim lblID As Integer = CType(item.FindControl("ID"), Integer)
' Dim txtBox As TextBox = DirectCast(item("ID").FindControl("ID"), TextBox)
' strAmount = txtBox.Text
' MsgBox(strAmount)
'Dim itemID As GridDataItem = TryCast(e.ItemID, GridDataItem)
'Dim itemValue As String = itemID("ID").Text
Response.Write(strAmount &
" "
)
Next
End
Sub