Reputation: 2911
I have grid that has a list of about 16 documents that can change depending on the person using the app. I've been asked to change three specific entries in the grid if they exist to links that open the documents.
How do I check for these three documents in the grid (column is called "Artifact") and insert the correct link for each of the three documents instead of the default text?
<asp:BoundField HeaderText="Artifact" DataField="ArtifactName" Visible="true" HeaderStyle-Width="300px" HeaderStyle-HorizontalAlign="Left"></asp:BoundField>
The same links are available in other parts of our website. Here is how they are implemented on other pages
<asp:LinkButton
ID="hypLnkAffidRelease2"
runat="server"
Text="Affidavit and Release form"
/>
var url = ResolveUrl("~/FormViewer.aspx");
this.lnkDownloadReleasefrm.Attributes.Add("onclick", " { popup=window.open('" + url + "?Form=4','Viewer','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=800, height=600'); popup.focus(); return false; }");
Upvotes: 1
Views: 662
Reputation: 3010
You can create TemplateField with two ItemTemplate (Label & HyperLink)
Label is more or less like BoundField once rendered.
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:Label ID="NoLink" runat="server"></asp:Label>
<asp:LinkButton ID="WithLink" runat="server" OnClick="Go_Click"/>
</ItemTemplate>
</asp:TemplateField>
When you bind the gridview
GridView.DataSouce = theData;
GridView.DataBind();
//index refers to the column number of the template field
for (int i=0; i<in GridView.Rows.Count; i++)
{
Label a = (Label)GridView.Rows[i].Cells[index].FindControl("NoLink");
LinkButton b = (LinkButton)GridView.Rows[i].Cells[index].FindControl("WithLink");
if (// link exists)
{
a.Visible = false;
b.Visible = true;
}
else)
{
a.Visible = true;
b.Visible = false;
}
}
Upvotes: 1