ietprofessional
Programmer
Hi Everyone,
I've created a repeater with linkbuttons that displays a through z. If you click on a link in the repeater a datagrid show only the record accounts that start with that letter. My problem now is I don't want all the links to be enabled if there are only record accounts that start with a, b, and c. I want to disable all of the ones that aren't available.
I'm getting an error on this line:
For Each linkButtonsInRepeater In rptLetters.Items
This is the exception:
System.InvalidCastException: Specified cast is not valid.
Can someone help?
THANKS!!!!
I've created a repeater with linkbuttons that displays a through z. If you click on a link in the repeater a datagrid show only the record accounts that start with that letter. My problem now is I don't want all the links to be enabled if there are only record accounts that start with a, b, and c. I want to disable all of the ones that aren't available.
I'm getting an error on this line:
For Each linkButtonsInRepeater In rptLetters.Items
This is the exception:
System.InvalidCastException: Specified cast is not valid.
Can someone help?
THANKS!!!!
Code:
Private Function checkForExistance(ByVal dt As DataTable)
Dim row As DataRow
Dim letter As String
Dim linkButtonsInRepeater As LinkButton = CType(rptLetters.FindControl("lnkLetter"), LinkButton)
'looping through a datatable
For Each row In dt.Rows
'Getting the first letter of column text
letter = CType(row(0), String)
letter = letter.Substring(0, 1)
' looping through the linkbuttons in repeater
For Each linkButtonsInRepeater In rptLetters.Items
If linkButtonsInRepeater.Text = letter Then
linkButtonsInRepeater.Enabled = True
End If
Next
Next
End Function
Private Sub rptLetters_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptLetters.ItemCreated
Dim letter As LinkButton = CType(e.Item.FindControl("lnkLetter"), LinkButton)
letter.Enabled = False
End Sub