I am using an OnItemDataBound event to attempt to activate a disabled button in a repeater. Quite simply, if the event is triggered, I know there are items in the repeater and therefore want to enable the button. Where I am getting stuck is on casting the button in the function so I can enable it. The relevant part of the repeater code is below:
<asp:Repeater ID="RptEnterHours" runat="server" DataSourceID="SQL_EmployeeGetTimesheet" ClientIDMode="Predictable" OnItemDataBound="RptEnterHours_Bound">
     '.....Irrelevant code.....
     <FooterTemplate>
          <asp:Button Enabled="false" ID="SubmitTimesheets" Text="Submit All Timesheets" OnClick="processTimesheetEntry" runat="server" OnClientClick="checkValues();" /> 
     </FooterTemplate>
</asp:Repeater>
This is my code behind:
Sub RptEnterHours_Bound(Sender As Object, e As RepeaterItemEventArgs)
    'Exposes the Submit All Timesheets button if timesheets are available.
    If (e.Item.ItemType = ListItemType.Item) Or _
        (e.Item.ItemType = ListItemType.AlternatingItem) Then
        Dim sButton As Button = TryCast(Me.FindControl("SubmitTimesheets"), Button)
        sButton.Enabled = True
    End If
End Sub
This and all other attempts has yielded the dreaded "Object reference not set to an instance of an object" message. Can anyone tell me what I am doing wrong and why my code behind won't find the button?
please try this i am sure it will help you.
    If e.Item.ItemType = ListItemType.Footer Then
        Dim btn as new button
        btn = CType(e.Item.FindControl("SubmitTimesheets"), Button)
        btn.enabled = true
    End If
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With