dynamically change webgrid CellTemplate hyperlink image

1 reply. Last post: December 23, 2012 11:05 PM by Bernard Xiang
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback

Hi,

I have a HyperLink in CellTemplate Column in Webgrid. I need to change the Image (navigateurl image) dynamically on InitializeRow event based on some condition. I tried changing the background image, but it didn't help. Please let me know the soultion for this.

Below is the code

==========

<ISWebGrid:WebGridColumn Caption="Error File" ColumnType="Template" Width="50px" Name="error">

<CellTemplate>

<asp:HyperLink ID="HyperLink1" runat="server" Target="_self" ImageUrl="~/Images/excel_icon.gif"

NavigateUrl='<%# String.Format("/ShowExcelFile.aspx?ID=CONV&File=E&Key={0}&logkey={1}",DataBinder.Eval(Container.DataItem, "aum_yardi_conv_key"),DataBinder.Eval(Container.DataItem, "aum_yardi_con_log_key")) %>'/>

</CellTemplate>

<HeaderStyle CssClass="gridHeadingNumberField" />

<CellStyle CssClass="gridContentTextField" HorizontalAlign="Center"/>

<FooterStyle CssClass="gridContentNumberField" />

</ISWebGrid:WebGridColumn>

 

In Initialize Event

====================

 if (e.Row.Type == RowType.Record)

        {

            WebGridCellCollection cells = e.Row.Cells;

            DataRowView drView = (DataRowView)e.Row.DataRow;

            int varError = Utility.GetIntegerValue(drView["error_file_length"]);

            if (varError == 0)

            {

                e.Row.Cells[3].TooltipText = noDataMsg + drView["post_date"].ToString();

                e.Row.Cells[3].GetTemplateContainer().BackImageUrl = "<img src='../../../Images/None.gif'/>";

            }

            else

            {

                e.Row.Cells[3].TooltipText = "View Error File";

            }

}

All times are GMT -5. The time now is 5:21 AM.
Previous Next