This is a migrated thread and some comments may be shown as answers.

Issue with EditImageUrl property of GridEditCommandColumn

3 Answers 181 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kumar
Top achievements
Rank 1
Kumar asked on 27 Mar 2012, 01:36 PM
Hi,

I am using Radgrid in one of my project ,i want to get editImageUrl and want to change it from code behind;
When i run the application and if i try to get the editimageurl i am getting the following error.
"Object reference not set to an instance of an object."
The html i am using is

<

 

MasterTableView DataKeyNames="Id" AutoGenerateColumns="false" CommandItemDisplay="Top">

<Columns>

<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" HeaderText="Edit column" ButtonType="ImageButton"

 

EditImageUrl = "

~/Alarm.png"

 

 >

<ItemStyle Width="50px" />

</telerik:GridEditCommandColumn>

......

if i try to get "EditImageUrl " of grideditcommandcoloumn it is throughting the above error.
Note:I tried to assign GridEditCommandColoumn from codebehind same issue is coming
Code:

GridEditCommandColumn edc = new GridEditCommandColumn();

edc.ButtonType =

GridButtonColumnType.ImageButton;

edc.EditImageUrl =

"~/Alarm.png";

Response.Write(edc.EditImageUrl);


Please help me on this.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Mar 2012, 01:54 PM
Hello Kumar,

You can access the EditColumn in ItemDataBound event and change the image as shown below.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridDataItem)
 {
   GridDataItem itm = (GridDataItem)e.Item;
   ImageButton btn = (ImageButton)itm["EditCommandColumn"].Controls[0];
   btn.ImageUrl = "~/Images/img.gif";
 }
}

Thanks,
Princy.
0
Kumar
Top achievements
Rank 1
answered on 27 Mar 2012, 01:58 PM
Hi,

Thanks for your reply.

Yes its working for me if i set it from CodeBehind,But the problem is when i try to get the EditImageUrl
of the RadGridEditCommandColumn its throwing the object ref error.

please try this yourself in aspx page

GridEditCommandColumn edc = new GridEditCommandColumn();

edc.ButtonType =

GridButtonColumnType.ImageButton;

edc.EditImageUrl =

"~/Alarm.png";

Response.Write(edc.EditImageUrl);



0
Princy
Top achievements
Rank 2
answered on 28 Mar 2012, 10:34 AM
Hello Kumar,

I am not sure what your exact requirement is. If you want to create GridEditCommandColumn from code behind you need to add that into RadGrid's column collection. Please try the following approach.
C#:
GridEditCommandColumn edc = new GridEditCommandColumn();
edc.ButtonType = GridButtonColumnType.ImageButton;
edc.EditImageUrl ="~/Alarm.png";
RadGrid1.MasterTableView.Columns.Add(edc);
Response.Write(edc.EditImageUrl);

Thanks,
Princy.
Tags
Grid
Asked by
Kumar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Kumar
Top achievements
Rank 1
Share this question
or