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>
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>