Custom hyperlink in a grid row

M

mark4asp

Here is an example of how to write a custom hyperlink in a grid row.
The hyperlink has 3 querystrings giving the ID a a record in the
database and a date range (from - to).

I'm putting this up here because I had some trouble figuring this out
and there are several examples of people who asked the question but
didn't get an answer.

This uses javascript and the GridView OnRowDataBound event.


<%@ Page Language="C#" %>

<script type="text/javascript">
function InflowDetails(ManagerID)
{
window.location.href = "details.aspx?id=" + ManagerID + "&df=" +
document.getElementById("selDateFrom").value + "&dt=" +
document.getElementById("selDateTo").value;
}
</script>

<asp:GridView ID="gvManagers" runat="server"
DataKeyNames="ManagerID"
OnRowDataBound="gvManagers_RowDataBound">
<Columns>
<asp:BoundField HeaderText="Manager" DataField="ManagerName"
SortExpression="ManagerName" >
<ItemStyle Width="240px" CssClass="gridHyperText"
ForeColor="black" />
</asp:BoundField>
...
...
</Columns>
</asp:GridView>

<script runat="server">

protected void gvManagers_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Text = "<a href='javascript:InflowDetails("
+ gvManagers.DataKeys[e.Row.DataItemIndex].Value + ");'>"
+ e.Row.Cells[0].Text + "</a>";
}
}

</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top