Hi,
We are using Telerik RadControls for ASP.NET Ajax version 2013.3.1114.45.
I have a radgrid with GridClientSelectColumn as first column to select rows, a checkbox column and Gridboundcolumn and the grid is in edit mode.
How to make a particular row read-only based on some condition ?
When the row becomes read-only, the following things should happen.
1. GridClientSelectColumn should not be visible for that row.
2. Checkbox should not be displayed, Yes or No text should be displayed instead of a tick-able checkbox
3. Editable textbox in gridboundcolumn should become readonly
Can you please help how to achieve ?
To hide the GridClientSelectColumn for some of the rows based on some condition, I did it as below in ItemDataBound event.
e.Item.Cells[2].Controls[0].visible = false;
But when the user clicks on the row (anywhere in the row), though the clientselectcheckbox is not visible, it is getting selected.
The following property returns true when the clientselectcolumn is not visible in a row and the user just clicked anywhere in the readonly row.
((System.Web.UI.WebControls.CheckBox)(gridDataItem.Cells[2].Controls[0])).Checked
We are using Telerik RadControls for ASP.NET Ajax version 2013.3.1114.45.
I have a radgrid with GridClientSelectColumn as first column to select rows, a checkbox column and Gridboundcolumn and the grid is in edit mode.
How to make a particular row read-only based on some condition ?
When the row becomes read-only, the following things should happen.
1. GridClientSelectColumn should not be visible for that row.
2. Checkbox should not be displayed, Yes or No text should be displayed instead of a tick-able checkbox
3. Editable textbox in gridboundcolumn should become readonly
Can you please help how to achieve ?
To hide the GridClientSelectColumn for some of the rows based on some condition, I did it as below in ItemDataBound event.
e.Item.Cells[2].Controls[0].visible = false;
But when the user clicks on the row (anywhere in the row), though the clientselectcheckbox is not visible, it is getting selected.
The following property returns true when the clientselectcolumn is not visible in a row and the user just clicked anywhere in the readonly row.
((System.Web.UI.WebControls.CheckBox)(gridDataItem.Cells[2].Controls[0])).Checked
5 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 28 Mar 2014, 12:52 PM
Hi Bhanu,
Please have a look into the sample code snippet which works fine at my end.
ASPX:
C#:
Thanks,
Princy.
Please have a look into the sample code snippet which works fine at my end.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
AutoGenerateColumns
=
"false"
AutoGenerateEditColumn
=
"true"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridClientSelectColumn
HeaderText
=
"select"
UniqueName
=
"sel"
>
</
telerik:GridClientSelectColumn
>
<
telerik:GridCheckBoxColumn
DataField
=
"Discontinued"
UniqueName
=
"Discontinued"
>
</
telerik:GridCheckBoxColumn
>
<
telerik:GridBoundColumn
DataField
=
"ProductName"
UniqueName
=
"ProductName"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
Selecting-AllowRowSelect
=
"true"
>
</
ClientSettings
>
</
telerik:RadGrid
>
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = (GridEditableItem)e.Item;
CheckBox chk = (CheckBox)item[
"sel"
].Controls[0];
chk.Visible =
false
;
CheckBox check = (CheckBox)item[
"Discontinued"
].Controls[0];
check.Enabled =
false
;
TextBox text = (TextBox)item[
"ProductName"
].Controls[0];
text.ReadOnly =
true
;
}
}
Thanks,
Princy.
0

Bhanu
Top achievements
Rank 1
answered on 28 Mar 2014, 03:51 PM
Hi,
As mentioned above, instead of disabled checkbox, 'Yes' or 'No' text should be displayed.
Checkbox should not be displayed, Yes or No text should be displayed instead of a disabled tick checkbox
I have tried to set Text property of checkbox, but both checkbox and its text are displayed.
Is it possible to display only text of checkbox and not the input control ?
Please let me know.
As mentioned above, instead of disabled checkbox, 'Yes' or 'No' text should be displayed.
Checkbox should not be displayed, Yes or No text should be displayed instead of a disabled tick checkbox
I have tried to set Text property of checkbox, but both checkbox and its text are displayed.
Is it possible to display only text of checkbox and not the input control ?
Please let me know.
0

Princy
Top achievements
Rank 2
answered on 31 Mar 2014, 04:02 AM
HI Bhanu,
We cant hide the CheckBox of a GridCheckBoxColumn. You may try something like as shown below to show checkbox as Yes/No.
C#:
Thanks,
Princy
We cant hide the CheckBox of a GridCheckBoxColumn. You may try something like as shown below to show checkbox as Yes/No.
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem edit = (GridEditableItem)e.Item;
CheckBox check = (CheckBox)edit[
"Discontinued"
].Controls[0];
check.Visible =
false
;
Label lbl =
new
Label();
lbl.ID =
"Lbl1"
;
edit[
"Discontinued"
].Controls.Add(lbl);
if
(check.Checked)
{
lbl.Text =
"Yes"
;
}
else
{
lbl.Text =
"No"
;
}
}
}
Thanks,
Princy
0

Bhanu
Top achievements
Rank 1
answered on 05 Apr 2014, 12:58 PM
Thanks for the response, that worked. But here is the problem. Even though the text "Yes" or "No" is displayed in place of a checkbox, the label is being lost when a server side operation occurs in which radgrid.rebind() is not called. Here is the scenario,
1. Grid is displayed in the page with the text "Yes" or "No" instead of a checkbox
2. Click on a button and button click is fired.
3. Do some validation with the data and then the validation fails
4. Display error message.
In this case, rebind() is not called, so the label is being disappeared in the grid after displaying the error message. Can you please verify and help me to achieve the required functionality ? Thanks for the help.
1. Grid is displayed in the page with the text "Yes" or "No" instead of a checkbox
2. Click on a button and button click is fired.
3. Do some validation with the data and then the validation fails
4. Display error message.
In this case, rebind() is not called, so the label is being disappeared in the grid after displaying the error message. Can you please verify and help me to achieve the required functionality ? Thanks for the help.
0

Princy
Top achievements
Rank 2
answered on 07 Apr 2014, 03:40 AM
Hi Bhanu,
Please try the following code snippet, it keeps the label value on postbacks.
C#:
Thanks,
Princy
Please try the following code snippet, it keeps the label value on postbacks.
C#:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem edit = (GridEditableItem)e.Item;
CheckBox check = (CheckBox)edit[
"Discontinued"
].Controls[0];
check.Visible =
false
;
Label lbl =
new
Label();
lbl.ID =
"Lbl1"
;
edit[
"Discontinued"
].Controls.Add(lbl);
}
}
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem edit = (GridEditableItem)e.Item;
CheckBox check = (CheckBox)edit[
"Discontinued"
].Controls[0];
Label lbl = (Label)edit.FindControl(
"Lbl1"
);
if
(check.Checked)
{
lbl.Text =
"Yes"
;
}
else
{
lbl.Text =
"No"
;
}
}
}
Thanks,
Princy