Hi all how can I disable edit option in radgrid. I would like to disable edit option for all the rows except first row. I would like to hide the edit icon or I would like to show alert as you can edit the old record
My design is as follows for edit icon
My design is as follows for edit icon
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
EditImageUrl
=
"images/Edit.gif"
UniqueName
=
"EmpID"
/>
12 Answers, 1 is accepted
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 06 Jul 2012, 09:06 AM
Hello,
Thanks,
Jayesh Goyani
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = e.Item
as
GridDataItem;
if
(item.ItemIndex == 0)
{
item[
"EmpID"
].Visible =
false
;
}
}
}
Thanks,
Jayesh Goyani
0
Dorababu
Top achievements
Rank 1
answered on 06 Jul 2012, 09:48 AM
Didn't worked ..
0
Princy
Top achievements
Rank 2
answered on 06 Jul 2012, 10:03 AM
Hi Dorababu,
Try the following code snippet to achieve your scenario.
C#:
Hope this helps.
Thanks,
Princy.
Try the following code snippet to achieve your scenario.
C#:
protected
void
radgrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = e.Item
as
GridDataItem;
if
(item.ItemIndex != 0)
{
item[
"EmpID"
].Enabled =
false
;
}
else
{
item[
"EmpID"
].Enabled =
true
;
}
}
}
Hope this helps.
Thanks,
Princy.
0
Dorababu
Top achievements
Rank 1
answered on 06 Jul 2012, 10:09 AM
I tried this which disable the selection of edit if it is not first row, but as per your given code I am unable to hide the edit image
protected
void
RadGrid2_PreRender(
object
sender, EventArgs e)
{
foreach
(GridDataItem item
in
RadGrid2.MasterTableView.Items)
{
if
(item.ItemIndex == 0)
{
item.Enabled =
true
;
}
else
{
item.Enabled =
false
;
}
}
}
0
Accepted
Princy
Top achievements
Rank 2
answered on 06 Jul 2012, 10:25 AM
Hi Dorababu,
Try the following code snippet to hide the edit icon.
C#:
Hope this helps.
Thanks,
Princy.
Try the following code snippet to hide the edit icon.
C#:
protected
void
radgrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = e.Item
as
GridDataItem;
if
(item.ItemIndex != 0)
{
item[
"EmpID"
].Visible =
false
;
}
else
{
item[
"EmpID"
].Visible =
true
;
}
}
}
Hope this helps.
Thanks,
Princy.
0
Dorababu
Top achievements
Rank 1
answered on 06 Jul 2012, 10:28 AM
Didn't work princy
0
Dorababu
Top achievements
Rank 1
answered on 06 Jul 2012, 12:34 PM
Changing the unique name of the control gives me the solution as per you suggested, is it possible to assign image at that place where we are setting the visibility to false
0
Princy
Top achievements
Rank 2
answered on 19 Jul 2012, 09:56 AM
Hi Dorababu,
I guess you want to show image in the rows where edit buttons visibility is set false.
C#:
Thanks,
Princy.
I guess you want to show image in the rows where edit buttons visibility is set false.
C#:
protected
void
Radgrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = e.Item
as
GridDataItem;
if
(item.ItemIndex != 0)
{
ImageButton btn = (ImageButton)item[
"EmpID"
].Controls[0];
btn.ImageUrl =
"Images/index.jpg"
;
btn.Enabled =
false
;
}
else
{
ImageButton btn = (ImageButton)item[
"EmpID"
].Controls[0];
btn.Visible =
true
;
}
}
}
Thanks,
Princy.
0
Stacy
Top achievements
Rank 1
answered on 30 Apr 2015, 01:19 PM
I am doing the same thing, except I want to not show the edit/delete on the first row but allow it on every other row. I've altered the code to do this. However, because the images are being hidden, it's throwing my first column value into where the "edit" icon would be, and my second column value into the first, etc, throwing off the alignment. Is there a way to hide the "edit" and keep the grid aligned?
0
Stacy
Top achievements
Rank 1
answered on 30 Apr 2015, 02:38 PM
I manged to solve this using:
item["editButton"].Text = "";
This will hide the edit image I was showing and still keep the grid columns aligned.
0
Stacy
Top achievements
Rank 1
answered on 30 Apr 2015, 02:50 PM
Actually, my last post does keep things in line but once u hit edit on another row, you get an exception thrown. Wish you could just hide the image and it'd be that easy.
0
Stacy
Top achievements
Rank 1
answered on 30 Apr 2015, 03:00 PM
this finally worked for me:
if
(e.Item
is
GridDataItem)
{
GridDataItem item = e.Item
as
GridDataItem;
if
(item.ItemIndex == 0)
{
if
(item.ItemIndex == 0)
{
ImageButton editButton = (ImageButton)item[
"editButton"
].Controls[0];
editButton.Visible =
false
;
ImageButton deleteButton = (ImageButton)item[
"deleteButton"
].Controls[0];
deleteButton.Visible =
false
;
}
}
}
if (e.Item is GridDataItem)
{
GridDataItem item = e.Item as GridDataItem;
if (item.ItemIndex == 0)
{
if (item.ItemIndex == 0)
{
ImageButton editButton = (ImageButton)item["editButton"].Controls[0];
editButton.Visible = false;
ImageButton deleteButton = (ImageButton)item["deleteButton"].Controls[0];
deleteButton.Visible = false;
}
}
}