I have a problem, i hope you can help me.
I am working with Radgrid and one gridTemplateColumn and when I clicked to a row I have to check row value and then change the image about the image button on this GridTemplateColumn, I'm using event ItemCommand and I don't Know how to change the image dynamycally.
Thanks for attention!!!
8 Answers, 1 is accepted

<
telerik:GridTemplateColumn
UniqueName
=
"Status"
HeaderText
=
"Status"
SortExpression
=
"Status"
AllowFiltering
=
"false"
>
<
ItemTemplate
>
<
asp:ImageButton
ID
=
"lnkStatus"
runat
=
"server"
ImageUrl
=
"#"
CommandName
=
"ChangeStatus"
CommandArgument='<%# Eval("ID") %>'></
asp:ImageButton
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName ==
"ChangeStatus"
)
{
GridDataItem item = (GridDataItem )e.Item;
// if You want to get column value then
string
strName = item[
"ColumnUNiqueName"
].Text;
// condition with dataKey
int
ID = Convert.ToInt32(item.GetDataKeyValue(
"ID"
));
if
(ID > 0)
// for example : if ID is graeter then Zero then change image.
{
// Change The Image
ImageButton lnkStatus = item .FindControl(
"lnkStatus"
)
as
ImageButton;
ImageButton.ImageUrl =
"New Image Url"
;
}
RadGrid1.Rebind();
}
}
let me know if any concern.
Thanks,
Jayesh Goyani

Thank you for your attention and your answer.
I did every steps that you wrote, but when I run application show me this message:
An
error has occurred.
DotNetNuke.Services.Exceptions.PageLoadException: DataBinding:
'System.Data.DataRowView' does not contain a property with the name 'ID'.
---> System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does
not contain a property with the name 'ID'. at
System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) at
System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts) at
System.Web.UI.DataBinder.Eval(Object container, String expression) at System.Web.UI.TemplateControl.Eval(String
expression) at
ASP.desktopmodules_html_catalogos_catalogos_ascx.__DataBinding__control20(Object
sender, EventArgs e) at System.Web.UI.Control.OnDataBinding(EventArgs e) at
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at
System.Web.UI.Control.DataBind() at System.Web.UI.Control.DataBindChildren() at
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at
System.Web.UI.Control.DataBind() at System.Web.UI.Control.DataBindChildren() at
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at
System.Web.UI.Control.DataBind() at Telerik.Web.UI.GridItem.SetupItem(Boolean
dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) at
Telerik.Web.UI.GridItemBuilder.InitializeItem(Int32 dataSourceIndex,
String& nextItemHierarchicalIndex, Boolean& itemIsInEditMode) at
Telerik.Web.UI.GridItemBuilder.CreateItems(GridGroupingContext group) at
Telerik.Web.UI.GridTableView.CreateItems(IEnumerator enumerator, GridColumn[]
columns, ControlCollection controls) at
Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) at
Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource,
Boolean useDataSource) at
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable
data) at
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable
data) at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments
arguments, DataSourceViewSelectCallback callback) at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at Telerik.Web.UI.GridTableView.PerformSelect() at
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() at
Telerik.Web.UI.GridTableView.DataBind() at Telerik.Web.UI.RadGrid.DataBind() at
Catalogos.Catalogos.Page_Load(Object sender, EventArgs e) at
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object
t, EventArgs e) at
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at
System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace
---
my code is as follows:
else if (e.CommandName == "ChangeStatus")
{
//Here I get information to change the image
DataAccesCatalogos act_des = new DataAccesCatalogos();
int st_currency;
st_currency = Convert.ToInt32((e.Item as GridDataItem)["status"].Text);
GridDataItem chng_image = (GridDataItem)e.Item;
//MONEDA ACTIVA
if (st_currency == 0)
{
ImageButton lnkstatus = chng_image.FindControl("lnkstatus") as ImageButton;
lnkstatus.ImageUrl = "~/images/eip_edit.gif";
RadGrid1.Rebind();
}
}
<
telerik:GridTemplateColumn
HeaderStyle-HorizontalAlign
=
"Center"
ItemStyle-HorizontalAlign
=
"Center"
>
<
ItemTemplate
>
<
asp:ImageButton
ID
=
"lnkstatus"
runat
=
"server"
ImageUrl
=
"#"
CommandName
=
"ChangeStatus"
CommandArgument='<%# Eval("ID") %>' Width="20" /></
ItemTemplate
>
</
telerik:GridTemplateColumn
>


<
MasterTableView
DataKeyNames
=
"ID"
>
// where ID is one of the field of your assigned datasource.
// for example : Select ID,Name from Uses
Thanks,
Jayesh Goyani

Yes I did that and it works, thank you for your answers.
Excuse me, one more question about this.
If I want to load one image depending of value form cell when RadGrid load, how can I do?
Thank you for all!!
Good day
Victor Hugo.

protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = e.Item
as
GridDataItem;
ImageButton lnkStatus = item.FindControl(
"lnkStatus"
)
as
ImageButton;
// condition with DataKeyName
if
(Convert.ToInt32(item.GetDataKeyValue(
"ID"
)) == 11)
{
lnkStatus.ImageUrl =
"Old Image Url 1"
;
}
else
{
lnkStatus.ImageUrl =
"Old Image Url 2"
;
}
//or
// condition with column value
if
(item[
"COlumnUNiqueName"
].Text ==
"Your Condition"
)
{
lnkStatus.ImageUrl =
"Old Image Url 1"
;
}
else
{
lnkStatus.ImageUrl =
"Old Image Url 2"
;
}
}
}
let me know if any concern.
Thanks,
Jayesh Goyani

But I want to do when the radgrid load, automatically, in postback and in his first load.
Thankyou

<
telerik:GridTemplateColumn
UniqueName
=
"Status"
HeaderText
=
"Status"
SortExpression
=
"Status"
AllowFiltering
=
"false"
>
<
ItemTemplate
>
<
asp:HiddenField
ID
=
"HiddenField1"
runat
=
"server"
/>
<
asp:ImageButton
ID
=
"lnkStatus"
runat
=
"server"
ImageUrl
=
"#"
CommandName
=
"ChangeStatus"
CommandArgument='<%# Eval("ID") %>'></
asp:ImageButton
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = e.Item
as
GridDataItem;
HiddenField HiddenField1 = item.FindControl(
"HiddenField1"
)
as
HiddenField;
if
(
string
.IsnullorEmpty(HiddenField1.Value)
{
ImageButton lnkStatus = item.FindControl(
"lnkStatus"
)
as
ImageButton;
// condition with DataKeyName
if
(Convert.ToInt32(item.GetDataKeyValue(
"ID"
)) == 11)
{
lnkStatus.ImageUrl =
"Old Image Url 1"
;
}
else
{
lnkStatus.ImageUrl =
"Old Image Url 2"
;
}
//or
// condition with column value
if
(item[
"COlumnUNiqueName"
].Text ==
"Your Condition"
)
{
lnkStatus.ImageUrl =
"Old Image Url 1"
;
}
else
{
lnkStatus.ImageUrl =
"Old Image Url 2"
;
}
HiddenField1.Value =
"XYZ"
;
}
}
}
Thanks,
Jayesh Goyani