2012-01-31 51 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; 
    } 
}