Hi Telerik
I want to get selected row, selected row column value from codebehind but without any checkbox selection,
I want to click on row and row should get selected and then post back to Codebehind function to get selected row value.
reply me please asap
Kind Regards:
Hariindarr Siingh
McConnell Dowell
I want to get selected row, selected row column value from codebehind but without any checkbox selection,
I want to click on row and row should get selected and then post back to Codebehind function to get selected row value.
reply me please asap
Kind Regards:
Hariindarr Siingh
McConnell Dowell
8 Answers, 1 is accepted
0
Accepted

Princy
Top achievements
Rank 2
answered on 01 Jun 2010, 06:06 AM
Hello Singh,
You can try the following code snippet to get the selected item. Set the EnablePostBackOnRowClick property to True so that the RadGrid1_SelectedIndexChanged() event will fire on selecting the row.
ASPX:
C#:
Thanks,
Priny.
You can try the following code snippet to get the selected item. Set the EnablePostBackOnRowClick property to True so that the RadGrid1_SelectedIndexChanged() event will fire on selecting the row.
ASPX:
<MasterTableView AutoGenerateColumns="false" DataKeyNames="EmployeeID"> |
<Columns> |
<telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="EmployeeID" /> |
<telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" UniqueName="FirstName" /> |
</Columns> |
</MasterTableView> |
<ClientSettings EnablePostBackOnRowClick="true" Selecting-AllowRowSelect="true"> |
</ClientSettings> |
C#:
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e) |
{ |
GridDataItem item=(GridDataItem)RadGrid1.SelectedItems[0]; |
string emp_id = RadGrid1.SelectedValue.ToString();//Retrieving primary key field values for selected items |
string name = item["FirstName"].Text; |
} |
Thanks,
Priny.
0

Ben
Top achievements
Rank 1
answered on 24 Nov 2010, 01:46 AM
Hi Princy
I have the same issue. I tried your code snippet. But its not working for me. I want to get the values in OnItemCreated even.
can you help me or anybody can help me?
I want to click on row and row should get selected and then click on "add new record" then insert form should popup and get couple of selected row values in the insert dropdownlist as selected.
I have created all the stuff, but I am not able to get selected values in OnItemCommand or OnItemCreated.
I tried in several ways
I have the same issue. I tried your code snippet. But its not working for me. I want to get the values in OnItemCreated even.
can you help me or anybody can help me?
I want to click on row and row should get selected and then click on "add new record" then insert form should popup and get couple of selected row values in the insert dropdownlist as selected.
I have created all the stuff, but I am not able to get selected values in OnItemCommand or OnItemCreated.
I tried in several ways
foreach
(GridDataItem it in RadGrid1.SelectedItems)
{
string opcode = it["OPCODE"].Text;
Response.Write(opcode);
}
not entering in this loop
0

Princy
Top achievements
Rank 2
answered on 24 Nov 2010, 06:51 AM
Hello Ben,
Since ItemCreated is fired before the item is data-bound, no data is available in the controls nested inside GridDataItem. So you can try the above code in ItemDataBound event to achieve your requirement.
Also please take a look at the following documentation.
Distinguishing the major differences between ItemCreated and ItemDataBound events
Thanks,
Princy.
Since ItemCreated is fired before the item is data-bound, no data is available in the controls nested inside GridDataItem. So you can try the above code in ItemDataBound event to achieve your requirement.
Also please take a look at the following documentation.
Distinguishing the major differences between ItemCreated and ItemDataBound events
Thanks,
Princy.
0

Princy
Top achievements
Rank 2
answered on 24 Nov 2010, 07:27 AM
Hello Ben,
And one more suggestion if you want to populate the controls in insertfrom with the selected row value, is using HiddenField control to save the selecteditem index.
Save the selecteditem index in a HiddenField control and by using the HiddenFiled value get the corresponding row and row values.
Thanks,
Princy.
And one more suggestion if you want to populate the controls in insertfrom with the selected row value, is using HiddenField control to save the selecteditem index.
Save the selecteditem index in a HiddenField control and by using the HiddenFiled value get the corresponding row and row values.
Thanks,
Princy.
0

Ben
Top achievements
Rank 1
answered on 24 Nov 2010, 04:04 PM
Hi Princy
Thanks for your answer
Can you give a sample code for your suggestion - Save the selecteditem index in a HiddenField control and by using the HiddenFiled value get the corresponding row and row values.
Thanks
Ben
Thanks for your answer
Can you give a sample code for your suggestion - Save the selecteditem index in a HiddenField control and by using the HiddenFiled value get the corresponding row and row values.
Thanks
Ben
0

Ben
Top achievements
Rank 1
answered on 24 Nov 2010, 04:42 PM
Hi Princy,
I did try it in OnItemDataBound. But still the same problem
not entering into this loop and not getting any values in RadGrid1.SelectedItems
Did you get my requirement? I have three DropDownlist(data binded with database) in insert form. I want to select a row(without check box) and click on add new record then popup insert form, Dropdownlist selected items should be the values in the selected row in radgrid. Everything is working fine now except dropdownlist selected item. Reason is: its not getting the values from selected row in radgrid. Give me a solution or give a sample code for your suggestion -Save the selecteditem index in a HiddenField control and by using the HiddenFiled value get the corresponding row and row values.
I did try it in OnItemDataBound. But still the same problem
not entering into this loop and not getting any values in RadGrid1.SelectedItems
Did you get my requirement? I have three DropDownlist(data binded with database) in insert form. I want to select a row(without check box) and click on add new record then popup insert form, Dropdownlist selected items should be the values in the selected row in radgrid. Everything is working fine now except dropdownlist selected item. Reason is: its not getting the values from selected row in radgrid. Give me a solution or give a sample code for your suggestion -Save the selecteditem index in a HiddenField control and by using the HiddenFiled value get the corresponding row and row values.
foreach
(GridDataItem item in RadGrid1.SelectedItems)
{
0

Princy
Top achievements
Rank 2
answered on 25 Nov 2010, 05:48 AM
Hello Bin,
Give a try with the following approach to achieve your requirement.
C#:
Thanks,
Princy.
Give a try with the following approach to achieve your requirement.
ASPX:
<
telerik:RadGrid
. . . .>
. . . . . . . . ..
<
ClientSettings
Selecting-AllowRowSelect
=
"true"
EnablePostBackOnRowClick
=
"true"
>
</
ClientSettings
>
</
telerik:RadGrid
>
<
asp:HiddenField
ID
=
"HiddenField1"
runat
=
"server"
/>
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName ==
"RowClick"
)
// set EnablePostBackOnRowClick property of RadGrid ClientSettings as 'True' to fire this
{
HiddenField1.Value = e.Item.ItemIndex.ToString();
//save the selected row index in a HiddenField
}
}
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
{
GridDataItem item = (GridDataItem)RadGrid1.Items[Convert.ToInt16(HiddenField1.Value)];
// getting selected Item
}
}
Thanks,
Princy.
0

Ben
Top achievements
Rank 1
answered on 25 Nov 2010, 06:47 PM
Hi Princy
Thank you very much
I have done. Now its working perfectly
Ben
Thank you very much
I have done. Now its working perfectly
Ben