显示一个asp:超链接url(如果有),否则,只显示一个radgrid

时间:2017-09-20 03:05:17

标签: c# asp.net linq-to-sql telerik-grid radgrid

我正在尝试添加一个指向telerik radgrid NestedViewTemplate的超链接。当有可用的超链接时,我得到了显示的超链接,但是,如果数据库中没有可用的超链接,我希望它显示“超链接不可用”。现在它显示“超链接不可用”作为超链接而不是文本。

的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;
        }

3 个答案:

答案 0 :(得分:0)

这有点复杂,但应该达到你想要的效果。我不知道如何直接将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;
}

答案 1 :(得分:0)

&#13;
&#13;
<asp:HyperLink ID="your id" runat="server">Hyperlink Not Available</asp:HyperLink>
&#13;
&#13;
&#13; 这应该工作

答案 2 :(得分:0)

enter image description here enter image description here

在下面的代码中,我让它为网站超链接工作并打开电子邮件的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