C# 在gridview中插入链接

C# 在gridview中插入链接,c#,asp.net,gridview,C#,Asp.net,Gridview,我有一个网格,它有一个大约16个文档的列表,这些文档可以根据使用应用程序的人的不同而变化。我被要求更改网格中的三个特定条目,如果它们存在于打开文档的链接中 如何在网格中检查这三个文档(列称为“工件”),并为这三个文档中的每一个插入正确的链接,而不是默认文本 <asp:BoundField HeaderText="Artifact" DataField="ArtifactName" Visible="true" HeaderStyle-Width="300px" HeaderSty

我有一个网格,它有一个大约16个文档的列表,这些文档可以根据使用应用程序的人的不同而变化。我被要求更改网格中的三个特定条目,如果它们存在于打开文档的链接中

如何在网格中检查这三个文档(列称为“工件”),并为这三个文档中的每一个插入正确的链接,而不是默认文本

    <asp:BoundField HeaderText="Artifact" DataField="ArtifactName" Visible="true" HeaderStyle-Width="300px"  HeaderStyle-HorizontalAlign="Left"></asp:BoundField>

我们网站的其他部分也有相同的链接。下面是它们在其他页面上的实现方式

<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; }");

var url=ResolveUrl(“~/FormViewer.aspx”);
this.lnkdownloadlereleasefrm.Attributes.Add(“onclick”,“popup=window.open”(“+url+”?Form=4”,“Viewer”,“toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resize=yes,copyhistory=no,width=800,height=600”);popup.focus();return false;});

您可以使用两个ItemTemplate(标签和超链接)创建TemplateField

渲染后,标签或多或少类似于BoundField

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

当您绑定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;
    }  
}
GridView.DataSouce=数据;
GridView.DataBind();
//索引是指模板字段的列号

对于(int i=0;i您可以使用两个ItemTemplate(标签和超链接)创建TemplateField

渲染后,标签或多或少类似于BoundField

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

当您绑定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;
    }  
}
GridView.DataSouce=数据;
GridView.DataBind();
//索引是指模板字段的列号

对于(int i=0;i您可以使用超链接对象。我不记得我是如何做到的,但在工作中我解决了类似的问题,通过这样做,从数据绑定信息调用函数,并创建/取消隐藏信息的超链接(如果该信息有效)。您可以使用超链接对象。我不记得我是如何做到的,但在工作中我解决了类似的问题是这样做,从数据绑定信息调用函数,并创建/取消隐藏信息的超链接(如果该超链接有效)。