I have a RadGrid with a GridClientSelectColumn and a bunch of GridBoundColumn.
Databinding is going on fine.
But, when click on the checkbox of the GridClientSelectColumn, I want to get the data of that particular Row. How will I do it??
What I have attempted is using the OnSelectedIndexChanged event. But the problem I am facing is, when ever I do a radGrid1.SelectedItems[0], it gives me OutofBounds error. I did EnablePostBackOnRowClick=true, in clientsettings, allowrowselect=true . The event is also being hit successfully, but I am not able get the selectedrows this way. Is there any other way to accomplish what I want to do??
Once again, I want to get the data of a particular Row which is selected. How can I do it??
Thanks in advance.
Yash
Databinding is going on fine.
But, when click on the checkbox of the GridClientSelectColumn, I want to get the data of that particular Row. How will I do it??
What I have attempted is using the OnSelectedIndexChanged event. But the problem I am facing is, when ever I do a radGrid1.SelectedItems[0], it gives me OutofBounds error. I did EnablePostBackOnRowClick=true, in clientsettings, allowrowselect=true . The event is also being hit successfully, but I am not able get the selectedrows this way. Is there any other way to accomplish what I want to do??
Once again, I want to get the data of a particular Row which is selected. How can I do it??
Thanks in advance.
Yash
4 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 14 Jul 2011, 05:01 AM
Hello Yash,
Try the following code snippet in SelectedIndexChanged event to get the contents of selected row.
C#:
Thanks,
Princy.
Try the following code snippet in SelectedIndexChanged event to get the contents of selected row.
C#:
protected
void
RadGrid1_SelectedIndexChanged(
object
sender, EventArgs e)
{
foreach
(GridDataItem item
in
RadGrid1.SelectedItems)
{
string
txt1 = item[
"ColumnUniqueName"
].Text;
}
}
Thanks,
Princy.
0

Yash
Top achievements
Rank 1
answered on 14 Jul 2011, 05:14 PM
Hi Princy, I see you giving this answer for lot of questions relating the Selected Row. Let me put my radgrid markup and the code behind that I am using to get row information.
Now, all I want is, data of the Row I select. I should not bother about any previously selected rows. I hope I am clear in this. The code snippet you gave is not working for me. I dont know why. Please see my mark up if I have messed up something. I have included some comments in the code behind which tells what problems I am facing.
regards
Yash
<
telerik:radgrid
runat
=
"server"
ID
=
"rgCOR"
AutoGenerateColumns
=
"False"
CellSpacing
=
"0"
GridLines
=
"None"
AllowSorting
=
"True"
onneeddatasource
=
"rgCOR_NeedDataSource"
AllowMultiRowSelection
=
"True"
onprerender
=
"rgCOR_PreRender"
onitemdatabound
=
"rgCOR_ItemDataBound"
onitemcommand
=
"rgCOR_ItemCommand"
>
<
clientsettings
EnablePostBackOnRowClick
=
"true"
>
<
selecting
allowrowselect
=
"True"
/>
<
Selecting
AllowRowSelect
=
"True"
></
Selecting
>
</
clientsettings
>
<
MasterTableView
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
FilterControlAltText
=
"Filter column column"
HeaderText
=
"Availablity"
UniqueName
=
"availability"
Visible
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridClientSelectColumn
FilterControlAltText
=
"Filter column column"
HeaderText
=
"AfC"
UniqueName
=
"FC"
>
</
telerik:GridClientSelectColumn
>
<
telerik:GridBoundColumn
FilterControlAltText
=
"Filter column2 column"
HeaderText
=
"ID"
UniqueName
=
"ID"
DataField
=
"ID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FilterControlAltText
=
"Filter column3 column"
HeaderText
=
"Name"
UniqueName
=
"DisplayName"
DataField
=
"DisplayName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FilterControlAltText
=
"Filter column4 column"
HeaderText
=
"Feature"
UniqueName
=
"FS"
DataField
=
"FS"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FilterControlAltText
=
"Filter column5 column"
HeaderText
=
"LQ"
UniqueName
=
"Usage"
DataField
=
"Usage"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FilterControlAltText
=
"Filter column8 column"
HeaderText
=
"old_R"
UniqueName
=
"old_R"
DataField
=
"Qty"
Visible
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
FilterControlAltText
=
"Filter TemplateColumn column"
UniqueName
=
"curr_R"
HeaderText
=
"curr_R"
>
<
ItemTemplate
>
<
telerik:RadComboBox
Runat
=
"server"
id
=
"rC"
Enabled
=
"False"
width
=
"50px"
>
</
telerik:RadComboBox
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
FilterControlAltText
=
"Filter column7 column"
HeaderText
=
"HT_cc"
UniqueName
=
"cc"
DataField
=
"cc"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
></
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
FilterMenu
EnableImageSprites
=
"False"
></
FilterMenu
>
<
HeaderContextMenu
CssClass
=
"GridContextMenu GridContextMenu_Default"
></
HeaderContextMenu
>
</
telerik:radgrid
>
protected
void
rgCOR_SelectedIndexChanged(
object
sender, EventArgs e)
{
foreach
(GridDataItem item
in
rgCOR.SelectedItems)
{
string
ss = item[
"ID"
].Text;//this is never hit. even if you have 100 rows selected
}
}
protected
void
rgCOR_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName ==
"RowClick"
)
{
GridDataItem temp = (GridDataItem)e.Item;
if
(e.Item.Selected ==
false
)
//this condition is always true even if you
//select a row or un-select a ro
w
{
e.Item.Selected =
true
;
}
}
}
Now, all I want is, data of the Row I select. I should not bother about any previously selected rows. I hope I am clear in this. The code snippet you gave is not working for me. I dont know why. Please see my mark up if I have messed up something. I have included some comments in the code behind which tells what problems I am facing.
regards
Yash
0
Hi Yash,
Do you attach the rgCOR_SelectedIndexChanged handler dynamically to the OnSelectedIndexChanged event of the grid. Because I don't see in the declaration of your grid. If you attach it dynamically make sure to do it on Page_Init event.
If you forgot to attach it, please add OnSelectedIndexChanged="rgCOR_SelectedIndexChanged" to the declaration of the grid and let me know if still not work properly.
Best wishes,
Vasil
the Telerik team
Do you attach the rgCOR_SelectedIndexChanged handler dynamically to the OnSelectedIndexChanged event of the grid. Because I don't see in the declaration of your grid. If you attach it dynamically make sure to do it on Page_Init event.
If you forgot to attach it, please add OnSelectedIndexChanged="rgCOR_SelectedIndexChanged" to the declaration of the grid and let me know if still not work properly.
Best wishes,
Vasil
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
0

Yash
Top achievements
Rank 1
answered on 18 Jul 2011, 03:44 PM
Thanks for the help, but that was not the solution. The table was getting rebound after my logic is executed. Thanks for the help. and for my requirement, "ItemCommand" event works much better. SelectIndexChanged doesnt work for my kind of requirement.