2017-05-25 94 views
0

我想更改一些为我写的代码。我想省略显示,其中tblResults.videoLink =“”在某些行中排除列 - SQL/Asp.Net

超链接将显示在表格中的“视频链接”,使人们可以点击它的超链接。我只希望单词/超链接“视频链接”出现在人们输入的行中。

的代码是微软SQL,但是写在ASPX文件。后端是VB,但有VB是相当多的空.. ASPX文件处理一切......

<h1>Recent Results</h1> 
    <asp:Panel ID="pnlMyWishes" runat="server"> 

     <asp:SqlDataSource ID="DSWishes" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>" SelectCommand="SELECT  TOP (100) PERCENT tblResults.wishID, tblResults.Player1AccountID, tblResults.Player2AccountID, tblResults.Player1Result, tblResults.Player2Result, tblResults.venue, tblResults.potSize, tblResults.player1Name, tblResults.player2Name, tblResults.videoLink, tblResults.date FROM tblResults ORDER BY tblResults.date DESC"> 
     </asp:SqlDataSource> 
     <asp:GridView ID="gdvWishes" width="100%" runat="server" AllowPaging="True" AutoGenerateColumns="False" CssClass="mGrid" DataKeyNames="wishID" DataSourceID="DSWishes" PageSize="20" AllowSorting="True"> 
      <AlternatingRowStyle CssClass="alt" /> 
      <Columns> 

       <asp:BoundField DataField="player1Name" HeaderText="Player 1" />  
       <asp:TemplateField HeaderText="Result"> 
        <ItemTemplate> 
         <asp:Label ID="lblP1" Text='<%# Eval("player1Result").ToString %>' runat="server" Visible="true"> 
         </asp:Label><asp:Label ID="lblVs" Text=" - " runat="server" Visible="true"></asp:Label> 
         <asp:Label ID="lblP2" Text='<%# Eval("player2Result").ToString %>' runat="server" Visible="true"></asp:Label> 
        </ItemTemplate> 
        <ItemStyle Width="17%" /> 
       </asp:TemplateField> 
       <asp:BoundField DataField="player2Name" HeaderText="Player 2" /> 

       <asp:BoundField DataField="potSize" HeaderText="Pot" /> 
       <asp:BoundField DataField="venue" HeaderText="Venue" /> 
       <asp:TemplateField ShowHeader="False"> 
        <ItemTemplate> 
         <asp:HyperLink ID="hypVideoLink" runat="server" NavigateUrl='<%# Eval("videoLink").ToString %>'>Video Link</asp:HyperLink> 
        </ItemTemplate> 
       </asp:TemplateField> 
      </Columns> 
     </asp:GridView> 
    </asp:Panel> 

回答

1

创建一个子像下面,与数据填充您的GridView的代码之后调用它。

Private Sub HideBlankURLs() 
    For Each r As GridViewRow in gdvWishes.Rows 
     If r.RowType = DataControlRowType.DataRow Then //Execute the code only for datarow, excluding footer and header 
      Dim hypURL As HyperLink 
      hypURL = r.Cells(5).FindControl("hypVideoLink") //Goes to the column of VideoURL, index 5 is counting from 0 to 5 
      If hypURL.NavigateURL = "" Then //Checks if the URL is blank, if it is then hide the hyperlink control 
       hypURL.Visible = False 
      End If 
     End If 
    Next r 
End Sub 

这将遍历所有行并查找该列中的控件,检查导航URL是否为空,然后隐藏该控件。

注意:更换(//)用单引号('),因为这么把它读成文本封闭字符,而不是评论。

+1

你是一个绝对的超级明星..完美的作品谢谢你。你可以在这里看到它.. http://www.poolmatchup.com/results.aspx – Eggybread