hi all
I use radgrid in my page with 2 GridBoundColumn
I want add 1 checkbox column to this grid that users can checked them.
then in my save button(that is in above of my page outside of grid),I check each checkbox of each row.if this is"checked",I save that row in my database
how can I do that
I use radgrid in my page with 2 GridBoundColumn
I want add 1 checkbox column to this grid that users can checked them.
then in my save button(that is in above of my page outside of grid),I check each checkbox of each row.if this is"checked",I save that row in my database
how can I do that
4 Answers, 1 is accepted
0

Jayesh Goyani
Top achievements
Rank 2
answered on 29 Jan 2011, 07:58 AM
<telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" Reorderable="false" />
foreach (GridItem item in radgrd1.MasterTableView.GetItems(new GridItemType[] { GridItemType.Item, GridItemType.AlternatingItem }))
{
GridDataItem dataitem = (GridDataItem)item;
TableCell cell = dataitem["ClientSelectColumn"];
CheckBox checkBox = (CheckBox)cell.Controls[0];
if (checkBox.Checked)
{
// do something
// get value from bound column
foreach (GridColumn col in radgrd1
.MasterTableView.Columns)
{
if (col.UniqueName == "boundcolumnUniueName")
{
string strtemp = dataitem[col.UniqueName].Text;
}
}
}
}
0

Jayesh Goyani
Top achievements
Rank 2
answered on 29 Jan 2011, 08:02 AM
<telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn" AllowFiltering="false">
<ItemTemplate>
<asp:CheckBox ID="Chkitem" runat="server" value='<%# Eval("VALUE")'></asp:CheckBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
foreach (GridDataItem dataItem in radgrd1.MasterTableView.Items)
{
CheckBox Chkitem = dataItem.FindControl("Chkitem") as CheckBox;
if (Chkitem .Checked == true)
{
striong checkBoxValue = Chkitem.Value;
string strTemp = dataItem.GetDataKeyValue("ID").ToString() ;
}
}
let me know if this code not help you...
<ItemTemplate>
<asp:CheckBox ID="Chkitem" runat="server" value='<%# Eval("VALUE")'></asp:CheckBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
foreach (GridDataItem dataItem in radgrd1.MasterTableView.Items)
{
CheckBox Chkitem = dataItem.FindControl("Chkitem") as CheckBox;
if (Chkitem .Checked == true)
{
striong checkBoxValue = Chkitem.Value;
string strTemp = dataItem.GetDataKeyValue("ID").ToString() ;
}
}
let me know if this code not help you...
0

samaneh
Top achievements
Rank 1
answered on 29 Jan 2011, 08:23 AM
thanks friends
I do that like your help but there is a new propblem:
my radgrid has "AllowPaging=true"
when user checked checkboxes of rows 1,2,3 of page 1 then go to page 2 and checked rows 3,4 and then return to page 1,all rows of page 1 are "unchecked".
how can I save them ,that when user change pages,these checked didn't clear
in gridview of asp.net ,In PageIndexChanging method,before user change page,I save index of checked rows in an array and after change page,read from that array and check them again but in radgrid we haven't PageIndexChanging method
do you have any soution for me that checkboxes didn't clear?
I do that like your help but there is a new propblem:
my radgrid has "AllowPaging=true"
when user checked checkboxes of rows 1,2,3 of page 1 then go to page 2 and checked rows 3,4 and then return to page 1,all rows of page 1 are "unchecked".
how can I save them ,that when user change pages,these checked didn't clear
in gridview of asp.net ,In PageIndexChanging method,before user change page,I save index of checked rows in an array and after change page,read from that array and check them again but in radgrid we haven't PageIndexChanging method
do you have any soution for me that checkboxes didn't clear?
0

Jayesh Goyani
Top achievements
Rank 2
answered on 31 Jan 2011, 07:43 AM
hi samaneh,
u may solve your issue with below code...
let me know if this code not help you...
Regards,
Jayesh Goyani
Radix web
u may solve your issue with below code...
<
script
type
=
"text/javascript"
>
var selected = {};
function RadGrid1_RowSelected(sender, args) {
var StudentId = args.getDataKeyValue("StudentId");
if (!selected[StudentId]) {
selected[StudentId] = true;
}
}
function RadGrid1_RowDeselected(sender, args) {
var StudentId = args.getDataKeyValue("StudentId");
if (selected[StudentId]) {
selected[StudentId] = null;
}
}
function pageLoad(sender, args) {
var dataItems = $find('<%=RadGrid1.ClientID %>').get_masterTableView().get_dataItems();
for (var i = 0, j = dataItems.length; i <
j
; i++) {
var
item
=
dataItems
[i];
if (selected[item.getDataKeyValue("StudentId")]) {
item.set_selected(true);
}
}
}
</script>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
>
<
MasterTableView
ClientDataKeyNames
=
"StudentId"
>
<
ClientSettings
Selecting-AllowRowSelect
=
"true"
EnableRowHoverStyle
=
"true"
>
<
ClientEvents
OnRowSelected
=
"RadGrid1_RowSelected"
OnRowDeselected
=
"RadGrid1_RowDeselected"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
let me know if this code not help you...
Regards,
Jayesh Goyani
Radix web