Hi,
I have 2 radgrids with checkbox for each row and ID column, now If I select some row in grid1 if grid2 has same rowID as grid1 then disable checkbox in grid2 for that ID. Please send me if you have any sample code.
Thanks in advance!!
I have 2 radgrids with checkbox for each row and ID column, now If I select some row in grid1 if grid2 has same rowID as grid1 then disable checkbox in grid2 for that ID. Please send me if you have any sample code.
Thanks in advance!!
5 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 30 Oct 2013, 09:24 AM
Hi Naresh,
Please try the sample code snippet. I have used CustomerID column ,to compare from both the grids.Hope this sample helps,let me know if any concern.
ASPX:
C#:
Thanks,
Princy
Please try the sample code snippet. I have used CustomerID column ,to compare from both the grids.Hope this sample helps,let me know if any concern.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"CheckBox1"
runat
=
"server"
AutoPostBack
=
"true"
OnCheckedChanged
=
"CheckBox1_CheckedChanged"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"OrderID"
DataField
=
"OrderID"
HeaderText
=
"OrderID"
/>
<
telerik:GridBoundColumn
DataField
=
"CustomerID"
HeaderText
=
"CustomerID"
UniqueName
=
"CustomerID"
/>
<
telerik:GridBoundColumn
DataField
=
"ShipCity"
HeaderText
=
"ShipCity"
UniqueName
=
"ShipCity"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
br
/>
<
br
/>
<
telerik:RadGrid
ID
=
"RadGrid2"
runat
=
"server"
>
<
MasterTableView
DataKeyNames
=
"CustomerID"
>
<
Columns
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"CheckBox2"
runat
=
"server"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"CustomerID"
DataField
=
"CustomerID"
HeaderText
=
"CustomerID"
/>
<
telerik:GridBoundColumn
DataField
=
"ContactName"
HeaderText
=
"ContactName"
UniqueName
=
"ContactName"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
C#:
protected
void
CheckBox1_CheckedChanged(
object
sender, EventArgs e)
{
CheckBox check = (CheckBox)sender;
GridDataItem item = (GridDataItem)check.NamingContainer;
string
id = item[
"CustomerID"
].Text;
RadGrid radgrid2 = (RadGrid)form1.FindControl(
"RadGrid2"
);
foreach
(GridDataItem ditem
in
radgrid2.Items)
{
string
customerid = ditem.GetDataKeyValue(
"CustomerID"
).ToString();
if
(
string
.Compare(customerid, id) == 0)
{
CheckBox chk = (CheckBox)ditem.FindControl(
"CheckBox2"
);
chk.Enabled =
false
;
}
}
}
Thanks,
Princy
0
Naresh
Top achievements
Rank 1
answered on 30 Oct 2013, 02:00 PM
Looks like it is working fine Thanks for the code!! but I have a problem here radgrids are in two different update panels how do I set trigger??
This is the checkbox error that I am getting
Error Message: A control with ID 'Election4CB' could not be found for the trigger in UpdatePanel 'UpdatePanel4'.
Because checkbox is inside telerik so update panel is not detecting event ID.
This is the checkbox error that I am getting
Error Message: A control with ID 'Election4CB' could not be found for the trigger in UpdatePanel 'UpdatePanel4'.
Because checkbox is inside telerik so update panel is not detecting event ID.
0
Naresh
Top achievements
Rank 1
answered on 30 Oct 2013, 03:28 PM
Never mind its working. Thanks!!
0
Naresh
Top achievements
Rank 1
answered on 03 Nov 2013, 08:54 PM
Hi Princy,
In the below code I have a issue my code is not enabling checkbox for RadGrid2 on Radgrid1 checkbox checked.
UI Code:
Code Behind:
In the below code I have a issue my code is not enabling checkbox for RadGrid2 on Radgrid1 checkbox checked.
UI Code:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"false"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
AllowPaging
=
"true"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"Check1"
runat
=
"server"
AutoPostBack
=
"true"
OnCheckedChanged
=
"Check1_CheckedChanged"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"OrderID"
DataField
=
"OrderID"
HeaderText
=
"OrderID"
/>
<
telerik:GridBoundColumn
DataField
=
"CustomerID"
HeaderText
=
"CustomerID"
UniqueName
=
"CustomerID"
/>
<
telerik:GridBoundColumn
DataField
=
"ShipCity"
HeaderText
=
"ShipCity"
UniqueName
=
"ShipCity"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
br
/>
<
telerik:RadGrid
ID
=
"RadGrid2"
runat
=
"server"
AutoGenerateColumns
=
"false"
OnNeedDataSource
=
"RadGrid2_NeedDataSource"
AllowPaging
=
"true"
>
<
MasterTableView
DataKeyNames
=
"CustomerID"
>
<
Columns
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"Check2"
runat
=
"server"
AutoPostBack
=
"true"
disabled
=
"disabled"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"OrderID"
DataField
=
"OrderID"
HeaderText
=
"OrderID"
/>
<
telerik:GridBoundColumn
DataField
=
"CustomerID"
HeaderText
=
"CustomerID"
UniqueName
=
"CustomerID"
/>
<
telerik:GridBoundColumn
DataField
=
"ShipCity"
HeaderText
=
"ShipCity"
UniqueName
=
"ShipCity"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
Code Behind:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data1 = new[] {
new { OrderID = 1, CustomerID =123,ShipCity = "Tampa"},
new { OrderID = 2, CustomerID =234,ShipCity = "Tampa"},
new { OrderID = 3, CustomerID =345,ShipCity = "Tampa"},
new { OrderID = 4, CustomerID =456,ShipCity = "Tampa"},
new { OrderID = 5, CustomerID =567,ShipCity = "Tampa"},
};
RadGrid1.DataSource = data1;
}
protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data2 = new[] {
new { OrderID = 1, CustomerID =123,ShipCity = "Tampa"},
new { OrderID = 2, CustomerID =234,ShipCity = "Tampa"},
new { OrderID = 3, CustomerID =345,ShipCity = "Tampa"},
new { OrderID = 4, CustomerID =456,ShipCity = "Tampa"},
new { OrderID = 5, CustomerID =567,ShipCity = "Tampa"},
};
RadGrid2.DataSource = data2;
}
protected void Check1_CheckedChanged(object sender, EventArgs e)
{
CheckBox check = (CheckBox)sender;
GridDataItem item = (GridDataItem)check.NamingContainer;
foreach (GridDataItem itemRG2 in RadGrid2.MasterTableView.Items)
{
CheckBox chk = (CheckBox)itemRG2.FindControl("Check2");
if (item["CustomerID"].Text == itemRG2["CustomerID"].Text)
{
if (check.Checked == true)
{
chk.Enabled = true;
}
else
{
chk.Enabled = false;
}
}
}
}
0
Princy
Top achievements
Rank 2
answered on 04 Nov 2013, 04:33 AM
Hi Naresh,
I guess you want the checkbox of the second radgrid to be disabled until the CheckBox of first RadGrid is checked. Please set the Enabled property of the CheckBox to false.
ASPX:
Thanks,
Princy
I guess you want the checkbox of the second radgrid to be disabled until the CheckBox of first RadGrid is checked. Please set the Enabled property of the CheckBox to false.
ASPX:
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"Check2"
runat
=
"server"
AutoPostBack
=
"true"
Enabled
=
"false"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
Thanks,
Princy