Link to home
Start Free TrialLog in
Avatar of brgdotnet
brgdotnetFlag for United States of America

asked on

How to hyperlink e.Rows.Cells[1].Text before it is displayed in the GridView control.

I am loading a GridView from a data source. Before the GridView is displayed, I need to hyperlink the
row cell item. How would I do that below for e.Rows.Cells[1].Text below? As you can see I am able to italicize the text, but I don't
know how to instead hyperlink it? Can an Asp.net expert help me out?

protected void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // Display the company name in italics.
                e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";

            }

        }
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, try below code which I have used. You don't need to bind it in RowDataBound event


<asp:GridView ID="gvStates" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
    RowStyle-BackColor="#A1DCF2" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000"
    runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:HyperLinkField DataTextField="StateName" DataNavigateUrlFields="StateId" DataNavigateUrlFormatString="~/SRerpot.aspx?StateId={0}"
            HeaderText="StateName" ItemStyle-Width = "200" />
        <asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width = "200" />
    </Columns>
</asp:GridView>

Open in new window

Avatar of brgdotnet

ASKER

No. It needs to be done using C#. Nothing in the Markup.
What we suggested IS part of the C# backend part ...
Hi,
Have you tried my suggestion ?

Regards,
Pawan