I want to be able to list organizations whether or not they have websites. If they have a website, I want the GridHyperLinkColumn text property = WEB and it would be the hyperlink to link to the organization's website. If they don't have a website, then I want the text property = "" or nothing.
Well, if you don't do anything, you get WEB in the website column whether or not they have a website - now the WEB for live hyperlinks are underlined and work whereas the others are just text with no underline - so it looks bad.
So I thought I would try to use some sort of conditional statement on the Itembound subroutine. I use a class named "Company" and "CheckForWeb" is an instantiation of that class. "GetCompany" is a function in the Company class that will get the company record from the database with the "CompanyID" (id) in the RadGrid row. Here is what I did:
Now, that resulted in companies that have websites having WEB in the website column and nothing if they didn't have a website BUT the link was not live - it was just text.
So after scouring the forum, I decided to add a couple of lines to the code to add a hyperlink as shown below.
That was really no good as I got the following alert error: Specified argument was out of the range of valid values. Parameter name: index - so I'm back to square one. Any help would be appreciated.
Well, if you don't do anything, you get WEB in the website column whether or not they have a website - now the WEB for live hyperlinks are underlined and work whereas the others are just text with no underline - so it looks bad.
So I thought I would try to use some sort of conditional statement on the Itembound subroutine. I use a class named "Company" and "CheckForWeb" is an instantiation of that class. "GetCompany" is a function in the Company class that will get the company record from the database with the "CompanyID" (id) in the RadGrid row. Here is what I did:
Protected
Sub
RadGrid1_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
GridItemEventArgs)
Handles
RadGrid1.ItemDataBound
If
TypeOf
e.Item
Is
GridDataItem
Then
Dim
item
As
GridDataItem =
DirectCast
(e.Item, GridDataItem)
Dim
id
As
String
= item.GetDataKeyValue(
"CompanyID"
).ToString
Dim
CheckForWeb
As
Company
CheckForWeb = Company.GetCompany(
CInt
(id))
' see if the object is populated
If
CheckForWeb.CompanyID.HasValue
Then
' check to see if there is a valid URL from the datafield WebsiteURL
If
CheckForWeb.WebsiteURL.Length > 10
Then
item(
"CompanyWebsite"
).Text =
"WEB"
Else
item(
"CompanyWebsite"
).Text =
""
End
If
End
If
End
If
End
Sub
Now, that resulted in companies that have websites having WEB in the website column and nothing if they didn't have a website BUT the link was not live - it was just text.
So after scouring the forum, I decided to add a couple of lines to the code to add a hyperlink as shown below.
Protected
Sub
RadGrid1_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
GridItemEventArgs)
Handles
RadGrid1.ItemDataBound
If
TypeOf
e.Item
Is
GridDataItem
Then
Dim
item
As
GridDataItem =
DirectCast
(e.Item, GridDataItem)
Dim
id
As
String
= item.GetDataKeyValue(
"CompanyID"
).ToString
Dim
CheckForWeb
As
Company
CheckForWeb = Company.GetCompany(
CInt
(id))
' see if the object is populated
If
CheckForWeb.CompanyID.HasValue
Then
' check to see if there is a valid URL from the datafield WebsiteURL
If
CheckForWeb.WebsiteURL.Length > 10
Then
item(
"CompanyWebsite"
).Text =
"WEB"
Dim
link
As
HyperLink =
DirectCast
(item(
"CompanyWebsite"
).Controls(0), HyperLink)
link.NavigateUrl = CheckForWeb.WebsiteURL
Else
item(
"CompanyWebsite"
).Text =
""
End
If
End
If
End
If
End
Sub
That was really no good as I got the following alert error: Specified argument was out of the range of valid values. Parameter name: index - so I'm back to square one. Any help would be appreciated.