1

我有一个带有网格视图的网络表单。在那个 Gridview 上有复选框。我的 gridview 中的所有项目都来自我的数据库。

我想知道的是,当我再次导航回该页面时,如何让 gridview 记住我的选择。

你能告诉我一个通用的方法吗?

谢谢!

4

3 回答 3

2

会话和 cookie
使用Session["value"]并将激活复选框的值放在那里。
然后onload()检查是否Session["value"]是某事并将 checkboxSomething 参数选中为真。现在没有电脑,所以我不能给你看代码。
希望你明白了。关于您在此处找到的更多会话:

http://msdn.microsoft.com/en-us/library/ms178581%28VS.100%29.aspx
于 2013-09-25T06:59:12.167 回答
0

正如您所说,gridview 中的所有项目都来自数据库,那么您可以先将您的选择保存到数据库中。因此,当您返回您的页面时,它将从 db 中填满,然后您再次获得填充的数据(选择)。

另一种方法是您可以将这些值存储在变量Session中或gridview 中,并在返回页面时获取它们。Cookierowcommand

于 2013-09-25T07:04:27.133 回答
0

你可以这样做:

ASPX:

<asp:GridView ID="grdView" runat="server" OnRowCommand="grdView_OnRowCommand">
 <Columns>
  <asp:TemplateField>
        <ItemTemplate>
           <asp:CheckBox ID="chkBox" runat="server"
CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' CommandName="chkbocCheck"
  AutoPostBack="true"   />
           </ItemTemplate>
  </asp:TemplateField>

CS :

protected void grdView_OnRowCommand (object sender, EventArgs e)
{ 
       string part = button.CommandArgument;   
           int rowIndex = Int32.Parse(part);
          CheckBox chk= null;
          if (rowIndex != -1)
            {
               chk= (CheckBox   )gvAlertSummary.Rows[rowIndex].Cells[0].FindControl("chkBox");
                // Write your logic here
 } 
}

希望这会帮助你。

于 2013-09-25T07:33:29.860 回答