在asp.net gridview中,启用分页。页面大小为10.当选中多个复选框时,复选框状态正在维护。但问题是当我们clcik只提交当前页面选择的记录时才添加到列表中。我想要添加entiere gridview seleted记录。
protected void gvFiling_DataBound(object sender, EventArgs e)
{
if (gvFiling.Rows.Count > 0 && ViewState["datakeys"] != null)
{
List < object > datakeys = (List < object > ) ViewState["datakeys"];
foreach(GridViewRow row in gvFiling.Rows)
((CheckBox) row.FindControl("cbxApply")).Checked = datakeys.Contains(gvFiling.DataKeys[row.RowIndex].Value);
}
}
protected void FullPostBack_Click(object sender, EventArgs e)
{
List < DataKey > applyList = new List < DataKey > ();
//there are 30 records. each page is having 10 records. selected checkbox records in the current page only added to list
//requirment is add the selected records from 3 pages.
foreach(GridViewRow row in gvFiling.Rows)
{
CheckBox cb = (CheckBox) row.FindControl("cbxApply");
if (cb != null) if (cb.Checked) applyList.Add(gvFiling.DataKeys[row.RowIndex]);
}
if (applyList.Count > 0)
{
GB.TLS.Business.ServiceHandler.FERCDocket.TariffFiling_DocketSearch_ApplyAssociations(applyList, this.AssociatedObjectType, this.AssociatedRecordID, SessionWrapper.UserModel.UserId);
gvFiling.DataBind();
}
if (ApplyFiling != null) ApplyFiling();
mpeSearch.Hide();
}
protected void gvFiling_PageIndexChanging(Object sender,GridViewPageEventArgs e)
{
列表&lt;对象&gt; datakeys = ViewState [“datakeys”]!= null? (List&lt; object&gt;)ViewState [“datakeys”]:new List&lt;对象&gt; ();
//添加选中的DataKeys
foreach(gvFiling.Rows中的GridViewRow行)
if(((CheckBox)row.FindControl(“cbxApply”))。checked)datakeys.Add(gvFiling.DataKeys [row.RowIndex] .Value);
else datakeys.Remove(gvFiling.DataKeys [row.RowIndex] .Value);
ViewState [“datakeys”] = datakeys;
}