0

我有带有复选框和复选框的列表视图控件,用于在更新面板中选择所有带有分页的选择 - 取消选择所有工作正常,除了在第 1 页中选择所有元素时选择所有元素但其他页面未选择任何想法

<asp:ListView ID="lstvw_all" runat="server" DataKeyNames="para"  >
                                        <LayoutTemplate>
                                            <table cellpadding="3" cellspacing="0" id="tbl_pers">
                                                <tr class="rsgridh">
                                                    <th>
                                                        رقم الإداري
                                                    </th>
                                                    <th>
                                                        الاسم
                                                    </th>
                                                    <th>
                                                        مهمة العمل
                                                    </th>
                                                    <th>
                                                        الفرع
                                                    </th>
                                                    <th>
                                                        الدورة
                                                    </th>
                                                    <th>
                                                        عدد المتدربين
                                                    </th>
                                                    <th>
                                                        المبلغ المستحق
                                                    </th>
                                                    <th>
                                                       <asp:CheckBox ID="cbSelectAll" runat="server" onclick="SelectAll(this);" />
                                                    </th>
                                                </tr>
                                                <tr id="itemPlaceHolder" runat="server">
                                                </tr>


                                            </table>
                                        </LayoutTemplate>
                                        <ItemTemplate>
                                            <tr class="rsgridi">
                                                <td>
                                                    <%# Eval("per_no") %>
                                                </td>
                                                <td>
                                                    <%# Eval("per_name") %>
                                                </td>
                                                <td>
                                                    <%# Eval("job_desc") %>
                                                </td>
                                                <td>
                                                    <%# Eval("org_label") %>
                                                </td>
                                                <td>
                                                    <%# Eval("course_desc") %>
                                                </td>
                                                <td>
                                                    <%# Eval("cnt_all") %>
                                                </td>
                                                <td>
                                                    <%# Eval("intial_cost") %>
                                                </td>
                                                <td>

                                                    <asp:CheckBox runat="server" ID="cbSelected"   Checked='<%# Selected(DataBinder.Eval(Container.DataItem,"para")) %>'  ToolTip='<%# DataBinder.Eval(Container.DataItem,"para") %>' >
                                                    </asp:CheckBox>
                                                </td>
                                            </tr>
                                        </ItemTemplate>
                                        <AlternatingItemTemplate>

                                         <tr class="rsgridai">
                                                <td>
                                                    <%# Eval("per_no") %>
                                                </td>
                                                <td>
                                                    <%# Eval("per_name") %>
                                                </td>
                                                <td>
                                                    <%# Eval("job_desc") %>
                                                </td>
                                                <td>
                                                    <%# Eval("org_label") %>
                                                </td>
                                                <td>
                                                    <%# Eval("course_desc") %>
                                                </td>
                                                <td>
                                                    <%# Eval("cnt_all") %>
                                                </td>
                                                <td>
                                                    <%# Eval("intial_cost") %>
                                                </td>
                                                <td>

                                                    <asp:CheckBox runat="server"   ID="cbSelected"  Checked='<%# Selected(DataBinder.Eval(Container.DataItem,"para")) %>' ToolTip='<%# DataBinder.Eval(Container.DataItem,"para") %>' s>
                                                    </asp:CheckBox>
                                                </td>
                                            </tr>
                                        </AlternatingItemTemplate>
                                    </asp:ListView>
4

2 回答 2

0

这是无法做到的 - 当您在第一页时,其余页面并不实际存在。

当您要求选择所有复选框时,就是您所看到的。更改页面后,其他复选框设置为默认值(可能未选中)

因此,重新设计您的用户界面以实现您的目标。

于 2012-12-02T17:53:02.703 回答
0

This can be done with a tweak ,this is for gridview ,convert this for listview or any other repeater control

Gridview HTML

<asp:GridView ID="GridView1" runat="server" 
AutoGenerateColumns="False" AllowPaging="True"  
PageSize="5" Width="324px" DataKeyNames="CategoryID" 
OnPageIndexChanging="GridView1_PageIndexChanging">
<Columns>
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" />
<asp:BoundField DataField="CategoryName" HeaderText="CategoryName" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

CS Codes

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
  RememberOldValues();
  GridView1.PageIndex = e.NewPageIndex;
  BindData();
  RePopulateValues();
}

And

private void RememberOldValues()
{
  ArrayList categoryIDList = new ArrayList();
  int index = -1;
  foreach (GridViewRow row in GridView1.Rows)
  {
   index = (int) GridView1.DataKeys[row.RowIndex].Value;
   bool result = ((CheckBox)row.FindControl("CheckBox1")).Checked;

  // Check in the Session
  if (Session[CHECKED_ITEMS] != null)
   categoryIDList = (ArrayList)Session[CHECKED_ITEMS];
  if (result)
  {
  if (!categoryIDList.Contains(index))
   categoryIDList.Add(index);
  }
  else
   categoryIDList.Remove(index);
  }
  if (categoryIDList != null && categoryIDList.Count > 0)
   Session[CHECKED_ITEMS] = categoryIDList;
}

And

private void RePopulateValues()
{
  ArrayList categoryIDList = (ArrayList)Session[CHECKED_ITEMS];
  if (categoryIDList != null && categoryIDList.Count > 0)
  {
  foreach (GridViewRow row in GridView1.Rows)
  {
   int index = (int)GridView1.DataKeys[row.RowIndex].Value;
  if (categoryIDList.Contains(index))
  {
   CheckBox myCheckBox = (CheckBox) row.FindControl("CheckBox1");
   myCheckBox.Checked = true;
  }
  }
  }
}

Bind Data Code

/* QUERY */
private const string QUERY_SELECT_ALL_CATEGORIES = "SELECT * FROM Categories";

private void BindData()
{
  SqlConnection myConnection = new SqlConnection(ConnectionString);
  SqlDataAdapter ad = new SqlDataAdapter(QUERY_SELECT_ALL_CATEGORIES,
  myConnection);
  DataSet ds = new DataSet();
  ad.Fill(ds, "Categories");
  GridView1.DataSource = ds;
  GridView1.DataBind();
}

For more details chk this Maintaining_State_of_CheckBoxes

于 2012-12-02T17:57:14.520 回答