0

I am making a reservation system and currently stuck on the following situation.

Basically I have a GridView which is loaded with the reservation ID and two LinkButton which opens a modal popup to enable the customer to view the details.

What I want to achieve is that when I click any LinkButton, it will show the ID from the first cell of a GridViewRow.

I have tried these methods here, here, here, and here but it still doesn't work. Is there any way to do it, Aside from using a SELECT Command and does involve async postback or if async postback is not possible with this, any fix recommended?

Here is my GridView code:

<asp:UpdatePanel runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="gvReservationSummaries"/>
            </Triggers>
            <ContentTemplate>
                <h2>Reservations</h2>
                <br />
                <asp:GridView ID="gvReservationSummaries" runat="server" 
                    AutoGenerateColumns="False" DataSourceID="SqlDataSource1" 
                    AllowPaging="True" ShowHeader="False" CellPadding="5" CellSpacing="5" 
                    onrowcommand="Gridview1_RowCommand">

                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server"><%# Eval("Master_Reservation_ID")%></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton runat="server" CommandName="ViewReservationDetails" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>'>View Reservation Details</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton runat="server" CommandName="ViewReceiptDetails" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>'>View Receipt Details</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>

                </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:DB_9E4ABD_GratchiOBRSConnectionString2 %>" 

                    SelectCommand="SELECT [Master_Reservation_ID] FROM [Master_Reservation] WHERE User_Unique_ID = @uuid">
                    <SelectParameters>
                        <asp:SessionParameter Name="uuid" SessionField="uid" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <br />
                <asp:Button ID="btnShowModal" runat="server" Text="Show Modal 1 (Debug Purposes Only)" onclick="btnShowModal_Click" />
                <!--Here, put the details of the reservaton, plus options to edit reservation.-->      
            </ContentTemplate>
        </asp:UpdatePanel> 
    </div>
</div>
<asp:Panel ID="reservationSummaryModal" runat="server" Width="500px" Height="500px" style="display: none; background-color:Black; color:#CCC;">
    <asp:Button ID="btnExitRs" runat="server" Text="Hide Modal (Debug Purposes Only)" onclick="btnExitAct_Click" />
    <asp:Label ID="lblReservationSummary" runat="server" Text="Label"></asp:Label>
</asp:Panel>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="HiddenField1" PopupControlID="reservationSummaryModal" BackgroundCssClass="modalBg" CancelControlID="btnExitRs">
</asp:ModalPopupExtender>
<asp:HiddenField ID="HiddenField1" runat="server" />

And here is my codebehind:

protected void Gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "ViewReservationDetails")
        {
            //GridViewRow gvr = gvReservationSummaries.Rows[Convert.ToInt32(e.CommandArgument)];
            gvReservationSummaries.SelectedIndex = Convert.ToInt32(e.CommandArgument);

            GridViewRow gvr = gvReservationSummaries.Rows[gvReservationSummaries.SelectedIndex];

            lblReservationSummary.Text = "The id is: " + gvr.Cells[0].Text.ToString();
            ModalPopupExtender1.Show();
        }

        else if (e.CommandName == "ViewReceiptDetails")
        {
            gvReservationSummaries.SelectedIndex = Convert.ToInt32(e.CommandArgument);

            GridViewRow gvr = gvReservationSummaries.Rows[gvReservationSummaries.SelectedIndex];

            lblReservationSummary.Text = "The id is: " + gvr.Cells[0].Text.ToString();
            ModalPopupExtender1.Show();
        }

        else
        {

        }
    }
Community
  • 1
  • 1
terrible-coder
  • 323
  • 2
  • 9
  • 18

0 Answers0