Webgrid How can I have a hyperlink- in a cel with an icon

4 replies. Last post: June 30, 2011 2:10 AM by Riendy Setiadi
Tags :
  • (None)
Neil TurnerMember

What I want to do is have an icon in a cell which denotes the value of the datamember of the cell (pending/active/cancelled) and for that icon to have a hyperlink on it based on the DataKeyValue of the row (appointmentid)


How can I acheive that?


1 attachment

All Replies

Hi Neil,

I'm currently still investigating your problem and need more time to provide a solution for you. For my added information, are you have another scenario beside using image hyperlink in WebGrid ?

I will let you know soon for an update.


Thank you for your patience.
Riendy

I don't have another scenario as this layout was stipulated by the client

Any news on this yet?

Hi Neil,

Thank you for your patience. 
To use an icon/image which have hyperlink in cell of WebGrid, first of all you have to set the column type to "HyperLink". Then input the codes that defines where hyperlink will be navigate and change the display text into icon/image tag in InitializeRow WebGrid event. For example, see snippet codes bellow :

For this example, the image would be existed on the second column.

  • For WebGridColumn (on clienSide): 
    <ISWebGrid:WebGridColumn Caption="CategoryName" DataMember="CategoryName" Name="CategoryName" Width="100px" ColumnType="HyperLink"
  • On ServerSide:
     protected void WebGrid1_InitializeRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e)
        {
            // To change a cell type into image.
            // Note that e.Row.Cells[0].Text is ColumnID.
            // Note that e.Row.Cells[1].Text is name of the image.
            WebGrid1.RootTable.Columns[1].HyperlinkDisplayText = " <img alt='" + "?id=" + e.R        ow.Cells[0].Text + "' src='" + e.Row.Cells[1].Text + "'/>";
            
            //To set a hyperlink format string. You can chage e.Row.Cells[0].Text into appoin        tmentID based on your scenario.
            WebGrid1.RootTable.Columns[1].HyperlinkFormatString = "http://www.google.co.id/s         earch?" + e.Row.Cells[0].Text;
        }
    

    Hope this helps.

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