如果可用,则显示 asp:hyperlink url,否则,仅在 radgrid 中显示文本

Display an asp:hyperlink url if one is available, otherwise, display text only in a radgrid

我正在尝试将超链接添加到我的 telerik radgrid NestedViewTemplate。当有可用的超链接时,我得到了要显示的超链接,但是,如果数据库中没有可用的超链接,我希望它显示 "Hyperlink Not Available." 现在它显示 "Hyperlink Not Available" 作为超链接而不是文本。

default.aspx

      <tr> 
        <td>
          <b>Website:</b>
            <asp:HyperLink NavigateUrl='<%# Bind("Hyperlink", "http://{0}") %>' Target="_blank" Text='<%# Bind("Hyperlink") %>'
             runat="server" ID="Hyperlink"></asp:HyperLink>
        </td>
 </tr>

default.aspx.cs

        using (PreferredVendorDataDataContext db = new PreferredVendorDataDataContext())
        {

            var supplierInfoForGrid = (from v in db.Vendors
                                       join c in db.ContactTables on v.ContactID equals c.ContactID
                                       join a in db.AddressTables on c.PrimaryAddressID equals a.AddressID
                                       join geoMarket in db.GeographicalMarkets on c.GeoMarket equals geoMarket.GeoMarketID
                                       join catList in db.CategoryListings on v.VendorID equals catList.VendorID
                                       join businCat in db.BusinessCategories on catList.CatID equals businCat.CatID
                                       //  join counDistrict in db.CouncilDistricts on c.DistrictID equals counDistrict.DistrictID
                                       where v.Verified == true
                                       orderby businCat.Category
                                       select new
                                       {
                                           businCatID = businCat.CatID,
                                           businCat = businCat.Category,
                                           companyName = v.CompanyName,
                                           description = v.Description,
                                           addressLine1 = a.AddressLine1,
                                           addressLine2 = a.AddressLine2,
                                           city = a.City,
                                           state = a.StateID,
                                           zip = a.Zip,
                                           phone = c.Phone,
                                           email = c.Email,
                                           Hyperlink = (c.Website == null ? "Hyperlink Not Available" : c.Website),

                                          geoMarket = geoMarket.GeoMarket,
                                           counDistrict = c.DistrictID.ToString()

                                       }).OrderBy(m => m.businCat).ThenBy(n => n.companyName).ToList();

            SupperlierGrid1.DataSource = supplierInfoForGrid;
        }

这有点复杂,但应该能达到你想要的效果。我不知道有什么方法可以直接将 asp 超链接链接到标签中。

<td>
          <b>Website:</b>
            <asp:HyperLink NavigateUrl='<%# Bind("Hyperlink", "http://{0}") %>' Target="_blank" Text='<%# Bind("Hyperlink") %>'
             runat="server" ID="Hyperlink"></asp:HyperLink>
            <asp:Label runat="Server" ID="EmptyHyperlink" Text="Hyperlink Not Available" Visible="false" />
        </td>

if (c.Website == null)
{
    Hyperlink.Visible = false;
    EmptyHyperlink.Visible = true;
}

<asp:HyperLink ID="your id" runat="server">Hyperlink Not Available</asp:HyperLink>
这应该有效

在下面的代码中,我将其用于网站超链接和打开电子邮件的 outlook。在前端用户将能够看到超链接或电子邮件是否可用并打开新页面(即网站或 outlook),否则,如果超链接或电子邮件不可用,它将显示文本。

default.aspx.cs

     select new
     {
       businCatID = businCat.CatID,
       businCat = businCat.Category,
       companyName = v.CompanyName,
       description = v.Description,
       addressLine1 = a.AddressLine1,
       addressLine2 = a.AddressLine2,
       city = a.City,
       state = a.StateID,
       zip = a.Zip,
       phone = c.Phone,
       email = (c.Email == null ? "No E-mail Address Available" : c.Email),
       Hyperlink = (c.Website == null ? "No Website Available" : c.Website),
       geoLocation = geoMarket.GeoMarket,
       counDistrict = c.DistrictID}).OrderBy(m => m.businCat).ThenBy(n => n.companyName).ToList();

default.aspx

       <NestedViewTemplate>
           <clientsettings>
              <ClientEvents OnRowClick="innerRowClick" />
           </clientsettings>

          <asp:Panel ID="NestedViewPanel" runat="server" CssClass="viewWrap" BackColor="white">
               <div class="descriptionWrap">

           <table>

               <tr>
                  <td>
                      <b>Website:</b>
                      <asp:HyperLink ID="HyperLink2" runat="server"  NavigateUrl='<%# Bind("Hyperlink", "http://{0}") %>' Target="_blank"
                       Text='<%# Eval("Hyperlink") %>' Visible='<%# Convert.ToBoolean(Eval("Hyperlink").ToString() != "No Website Available" ? "True" : "False") %>'>
                      </asp:HyperLink>
                        <asp:Label ID="Label2" runat="server"  Text='<%# Eval("Hyperlink") %>' Visible='<%#  Convert.ToBoolean((Eval("Hyperlink").ToString() != "No Website Available" ? "False" : "True")) %>'>
                        </asp:Label>                                                            
                  </td>
             </tr>

             <tr>
                <td>
                      <b>E-mail Address:</b>
                      <asp:HyperLink ID="HyperLink1" runat="server"  NavigateUrl='<%# Bind("email", "mailto:{0}") %>' Target="_blank"
                       Text='<%# Eval("email") %>' Visible='<%# Convert.ToBoolean(Eval("email").ToString() != "No E-mail Address Available" ? "True" : "False") %>'>
                      </asp:HyperLink>
                         <asp:Label ID="Label3" runat="server"  Text='<%# Eval("email") %>' Visible='<%#  Convert.ToBoolean((Eval("email").ToString() != "No E-mail Address Available" ? "False" : "True")) %>'>
                         </asp:Label> 
               </td>
             </tr>
        </table>

      </div>
       </asp:Panel>
           </NestedViewTemplate>


  [1]: https://i.stack.imgur.com/jVhra.png
  [2]: https://i.stack.imgur.com/BGji2.png