I currently have a Grid View with two buttons that I have added using the following code;

<asp:GridView ID="gvResults" AutoGenerateColumns="False" runat="server" Font-Size="small"
        DataKeyNames="BeachHutID" OnRowDataBound="gvResults_RowDataBound" CssClass="BBCSearch">
        <Columns>
            <asp:BoundField DataField="BeachHutID" SortExpression="BeachHutID" Visible="false">
            </asp:BoundField>
            <asp:ImageField DataImageUrlField="HutImage" ItemStyle-Width="1%" ReadOnly="true" />
            <asp:BoundField HeaderText="Facilities" DataField="Facilities" Visible="false"></asp:BoundField>
            <asp:BoundField HeaderText="Info" DataField="Info" Visible="false"></asp:BoundField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:PlaceHolder ID="lblHolder" runat="server"></asp:PlaceHolder>
                    <br />
                    <asp:PlaceHolder ID="imgHolder" runat="server"></asp:PlaceHolder>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button ID="btnHire" CommandArgument='<%# Eval("BeachHutID") %>' runat="server"
                        Text="Hire Beach Hut" OnClick="Hire_Click" />
                        <asp:Button ID="ButtonLoggedIn" CommandArgument='<%# Eval("BeachHutID") %>' runat="server"
                        Text="Login to Hire Beach Hut" OnClick="Login_Redirect" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

What I want to happen is if the user is logged in, the btnHire button should be enabled and showing and if they're not logged in, ButtonLoggedIn is showing and btnHire is hidden. This is the code I have at the moment;

Public Sub PopulateGrid()


    Dim AvailableHuts As New DataTable


    AvailableHuts = GetData()


    gvResults.DataSource = AvailableHuts
    gvResults.DataBind()
    gvResults.Enabled = True

    'If statement controlling the enabling and disabling of the Beach Hut booking button

    If Session("LoginID") = "" Then
        For Each rowItem As GridViewRow In gvResults.Rows
            rowItem.Cells(5).Enabled = True
        Next
    End If

    lblCaption.Text = "Your search returned " + CStr(AvailableHuts.Rows.Count) + " results"

End Sub

At the moment both buttons are enabled at all times and I'm not sure what I need to add/changed to get the desired result.

I have picked up this project recently and have very beginner knowledge of ASP.NET and VB.NET.

Any assistance would be much appreciated.

Thanks

Related posts

Recent Viewed