2012-01-31 75 views
1

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

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

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

您可以使用一个超链接对象。我不记得我是如何做到的,但在工作中,我通过这样做解决了类似的问题,从数据绑定信息中调用函数,并在信息有效时创建/取消隐藏信息的超链接。 – deed02392 2012-01-31 21:23:48

回答

1

您可以创建模板列有两个ItemTemplate中(标签&超链接)

标签或多或少类似的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; 
    } 
}