简体   繁体   中英

How to maintain page index information such as radiobuttonlist after navigating to next page?

I have a "survey-like" project where my grid include a list of names with radiobuttonlist 1-10 choice for user to select. The grid is having a page size of just 1 for every question.

How is it possible I can navigate back and see my result selected? I have been researching for long, some says session and some use query string. To elaborate more on what I actually wants, please take a look at this link : http://www.aspsnippets.com/Articles/Preserving-state-of-Checkboxes-while-paging-in-ASP.Net-GridView-Control.aspx

How can I achieve the checkbox as radiobuttonlist in the above project?

My code:

    protected void SubmitAppraisalGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        SubmitAppraisalGrid.PageIndex = e.NewPageIndex;
        ArrayList list = FindValues(this.Page);

        DataTable dt = (DataTable)ViewState["QuestionTable"];
        SubmitAppraisalGrid.DataSource = dt;
        SubmitAppraisalGrid.DataBind();
    }

design:

<asp:GridView ID="SubmitAppraisalGrid" runat="server" AllowPaging="True" 
        AutoGenerateColumns="False" BorderWidth="0px" 
        OnPageIndexChanging="SubmitAppraisalGrid_PageIndexChanging" 
        onrowcreated="SubmitAppraisalGrid_RowCreated" PageSize="1" ShowHeader="False" 
        style="margin-right: 0px">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Label ID="QuestionLbl" runat="server" Text='<%# Bind("Question")%>'></asp:Label>
                            <br />
                            <br />
                            <asp:GridView ID="StaffAppraisalGrid" runat="server" 
                        AutoGenerateColumns="False" BorderWidth="0px" CellPadding="4" CellSpacing="2" 
                        GridLines="Horizontal">
                                <Columns>
                                    <asp:BoundField DataField="StaffName" HeaderText="Name">
                                    <HeaderStyle HorizontalAlign="Left" />
                                    </asp:BoundField>
                                    <asp:TemplateField HeaderText="Rate">
                                        <ItemTemplate>
                                            <asp:RadioButtonList ID="RadioList" runat="server" CellPadding="8" 
                                                DataSource='<%# Bind("RadioButtonList")%>' RepeatDirection="Horizontal">
                                            </asp:RadioButtonList>
                                        </ItemTemplate>
                                        <HeaderStyle HorizontalAlign="Left" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Remarks">
                                        <ItemTemplate>
                                            <asp:TextBox ID="RemarksTbx" runat="server" CssClass="remarkTbx" 
                                                onKeyDown="limitText(this,500);" onkeypress="return check(event)" 
                                                onKeyUp="limitText(this,500);" onMouseDown="return DisableControlKey(event)" 
                                                Text='<%# Bind("RemarkTbx")%>' TextMode="MultiLine"></asp:TextBox>
                                        </ItemTemplate>
                                        <HeaderStyle HorizontalAlign="Left" />
                                    </asp:TemplateField>
                                </Columns>
                    </asp:GridView>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <PagerStyle HorizontalAlign="Center" />
    </asp:GridView>

I think using Session("QuestionTable") will work as you describe, the user will be able to Navigate back to the page and see what they selected. You'll just have to update it with the selections they made with a postback before they move on to a new page.

On your PageLoad (or some button Click Event) retrieve the values from the RadioButtons, update your QuestionTable, then put it into Session Memory.

    Session("QuestionTable") = dt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM