I'm trying to add a hyperlink to my telerik radgrid NestedViewTemplate. I got the hyperlink to display when there is one available, however, if there is no hyperlink available from the database I want it to display "Hyperlink Not Available." Right now it displays "Hyperlink Not Available" as a hyperlink and not text.
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;
}
In the code below, I got it to work for Website hyperlinks and to open outlook for the e-mails. In the front-end users will be able to see if hyperlinks or e-mails are available and open the new page(that is either website or outlook), otherwise, it will display text if hyperlink or email is not available.
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.sstatic.net/jVhra.png
[2]: https://i.sstatic.net/BGji2.png