【问题标题】:How to maintain page index information such as radiobuttonlist after navigating to next page?导航到下一页后如何维护单选按钮列表等页面索引信息?
【发布时间】:2018-08-29 05:21:35
【问题描述】:

我有一个“类似调查”的项目,其中我的网格包含一个名称列表,其中包含单选按钮列表 1-10 选项供用户选择。对于每个问题,网格的页面大小仅为 1。

我怎么可能返回并看到我的结果被选中?我研究了很长时间,有人说会话,有人使用查询字符串。要详细说明我真正想要的内容,请查看此链接:http://www.aspsnippets.com/Articles/Preserving-state-of-Checkboxes-while-paging-in-ASP.Net-GridView-Control.aspx

如何在上述项目中实现复选框作为单选按钮列表?

我的代码:

    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();
    }

设计:

<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>

【问题讨论】:

    标签: c# asp.net visual-studio-2010


    【解决方案1】:

    我认为使用 Session("QuestionTable") 将按照您的描述工作,用户将能够导航回页面并查看他们选择的内容。在他们进入新页面之前,您只需使用他们通过回发所做的选择对其进行更新。

    在您的 PageLoad(或某些按钮单击事件)上从 RadioButtons 中检索值,更新您的 QuestionTable,然后将其放入会话内存中。

        Session("QuestionTable") = dt
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-15
      • 2020-08-04
      • 2021-08-19
      • 1970-01-01
      • 2019-12-28
      • 2010-10-08
      • 1970-01-01
      相关资源
      最近更新 更多