I tried to get the ID value from selected row in a RadGrid. But what I try, I keep the value " ".
The data is collected by a WCF webservice by the way.
Below the ASP code I use:
<
telerik:RadScriptManager
ID
=
"RadScriptManager"
runat
=
"server"
EnableHandlerDetection
=
"false"
>
<
Scripts
>
</
Scripts
>
</
telerik:RadScriptManager
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"gridSimCards"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"gridSimCards"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
div
class
=
"pagetitle"
><
asp:Literal
ID
=
"ltrPageTitle"
runat
=
"server"
/></
div
>
<
telerik:RadGrid
ID
=
"gridSimCards"
runat
=
"server"
EnableViewState
=
"true"
AutoGenerateColumns
=
"false"
Skin
=
"Silk"
AllowFilteringByColumn
=
"true"
AllowPaging
=
"true"
PageSize
=
"10"
AllowSorting
=
"true"
OnSelectedIndexChanged
=
"gridSimCards_SelectedIndexChanged"
>
<
ClientSettings
EnablePostBackOnRowClick
=
"true"
EnableRowHoverStyle
=
"true"
AllowColumnsReorder
=
"true"
>
<
Selecting
AllowRowSelect
=
"true"
/>
<
Resizing
AllowColumnResize
=
"true"
ShowRowIndicatorColumn
=
"true"
/>
<
DataBinding
SelectMethod
=
"GetSimCards"
Location
=
"../WebServices/GridDataProvider.svc"
SelectCountMethod
=
"GetSimCardsCount"
MaximumRowsParameterName
=
"rowCount"
StartRowIndexParameterName
=
"rowStart"
SortParameterName
=
"sorter"
SortParameterType
=
"List"
FilterParameterName
=
"filter"
FilterParameterType
=
"List"
/>
</
ClientSettings
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
AlwaysVisible
=
"true"
/>
<
MasterTableView
Width
=
"100%"
DataKeyNames
=
"ID"
>
<
Columns
>
<
telerik:GridBoundColumn
UniqueName
=
"ID"
DataField
=
"ID"
HeaderText
=
"#"
DataType
=
"System.String"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Provider"
HeaderText
=
"Provider"
DataType
=
"System.String"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Country"
HeaderText
=
"Land"
DataType
=
"System.String"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"SIMNumber"
HeaderText
=
"SIM-nummer"
DataType
=
"System.String"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"TelephoneNumber"
HeaderText
=
"Telefoonnummer"
DataType
=
"System.String"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ContactPeriodFrom"
HeaderText
=
"Contract van"
DataType
=
"System.DateTime"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ContractPeriodTill"
HeaderText
=
"Contract tot"
DataType
=
"System.DateTime"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"InUse"
HeaderText
=
"In gebruik"
DataType
=
"System.Boolean"
></
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
The code below is use to get the value of the selected ID column:
protected
void
gridSimCards_SelectedIndexChanged(
object
sender, EventArgs e)
{
int
selectedRowIdx = gridSimCards.SelectedItems[0].ItemIndex;
GridDataItem selectedItem = (GridDataItem)gridSimCards.MasterTableView.Items[selectedRowIdx];
string
str = selectedItem[
"ID"
].Text;
}
What am I doing wrong, or what am I missing?