I want to display a hyperlink on a datagrid row if a certain value in that row meets a criteria. For the sake of discussion, let's say I have a datagrid w/ three template colums. The datagrid is bound to a dataset. The first column contains a unique ID field, the second column contains a label for a value and the third column is where I want to optionally display my hyperlink.
If the value in the second column is, let's say, "Foreign" then I want to display a hyperlink in the third column that will redirect the user to a page and pass to that page the value in the first column.
For example, if the first column contains "1234", the second column contains "Foreign", then I want a hyperlink in the third column to be something like "map.aspx?id=1234". Below are how I have my columns set up so far. I would be very grateful for any help you may provide.
<asp:datagrid id="DataGrid1" runat="server" Font-Size="10pt" AlternatingItemStyle-BackColor="#ffffcc" autogeneratecolumns="False" DataKeyField="IDNbr" OnEditCommand="DataGrid_Edit" OnCancelCommand="DataGrid_Cancel" OnUpdateCommand="DataGrid_Update" AllowPaging="True" PageSize="15">
<AlternatingItemStyle BackColor="#FFFFCC"></AlternatingItemStyle>
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="IDNbr" DataNavigateUrlFormatString="Roundhouse.aspx?IDNbr={0}" DataTextField="IDNbr" HeaderText="ID #" NavigateUrl="Roundhouse.aspx">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="Yellow" BackColor="DarkBlue"></HeaderStyle>
</asp:HyperLinkColumn>
<asp:TemplateColumn>
<HeaderStyle Font-Bold="True" ForeColor="Yellow" BackColor="DarkBlue"></HeaderStyle>
<HeaderTemplate>
Debt Type
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblFgnDom" Runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FgnDom" %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderStyle ForeColor="Yellow" BackColor="DarkBlue"></HeaderStyle>
<ItemTemplate>
<asp:HyperLink ID="AmortLink" Runat="server">
<asp:Label ID="lblAmort" Runat="server"></asp:Label>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
If the value in the second column is, let's say, "Foreign" then I want to display a hyperlink in the third column that will redirect the user to a page and pass to that page the value in the first column.
For example, if the first column contains "1234", the second column contains "Foreign", then I want a hyperlink in the third column to be something like "map.aspx?id=1234". Below are how I have my columns set up so far. I would be very grateful for any help you may provide.
<asp:datagrid id="DataGrid1" runat="server" Font-Size="10pt" AlternatingItemStyle-BackColor="#ffffcc" autogeneratecolumns="False" DataKeyField="IDNbr" OnEditCommand="DataGrid_Edit" OnCancelCommand="DataGrid_Cancel" OnUpdateCommand="DataGrid_Update" AllowPaging="True" PageSize="15">
<AlternatingItemStyle BackColor="#FFFFCC"></AlternatingItemStyle>
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="IDNbr" DataNavigateUrlFormatString="Roundhouse.aspx?IDNbr={0}" DataTextField="IDNbr" HeaderText="ID #" NavigateUrl="Roundhouse.aspx">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="Yellow" BackColor="DarkBlue"></HeaderStyle>
</asp:HyperLinkColumn>
<asp:TemplateColumn>
<HeaderStyle Font-Bold="True" ForeColor="Yellow" BackColor="DarkBlue"></HeaderStyle>
<HeaderTemplate>
Debt Type
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblFgnDom" Runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FgnDom" %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderStyle ForeColor="Yellow" BackColor="DarkBlue"></HeaderStyle>
<ItemTemplate>
<asp:HyperLink ID="AmortLink" Runat="server">
<asp:Label ID="lblAmort" Runat="server"></asp:Label>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>