在GridView控件中进行分页时CheckBox的状态 [英] State of CheckBoxes While Paging in a GridView Control
问题描述
嗨!
我在使用分页控件的GridView中遇到 CheckBox
的问题...
我有一个 GridView
,带 CheckBox
和分页控制......
当我在第一页选择 CheckBox
并选择一个 CheckBox
在分页2中很快..
我需要多少总和 CheckBox
es我在 GridView
中选择了分页控件..
愿任何人帮助我解决这个问题请从2天开始尝试...
Hi!
I'm have some problem with CheckBox
in GridView with paging control...
I'm having one GridView
with CheckBox
and paging control...
When I'm selecting the CheckBox
in page one and selecting the one CheckBox
in paging 2 and soon..
I need sum of how many CheckBox
es I selected in the GridView
with paging control..
May anyone help me from this problem please I'm trying from 2 days onwards...
推荐答案
protected void GridView1_PreRender(object sender, EventArgs e)
{
if (Session["page" + GridView1.PageIndex] != null)
{
int count = Convert.ToInt32(ViewState["total"]);
CheckBox chb;
bool[] values = (bool[])Session["page" + GridView1.PageIndex];
for (int i = 0; i < GridView1.Rows.Count; i++)
{
chb = (CheckBox)GridView1.Rows[i].FindControl("chkStatus");
chb.Checked = values[i];
}
}
}
protected void GridView1_PageIndexChanging(object sender,GridViewPageEventArgs e)
{
Response.Write(GridView1.PageIndex.ToString());
int d = GridView1.PageCount;
bool [] values = new bool [GridView1.PageSize];
CheckBox chb;
int count = Convert。 ToInt32(ViewState [total]);
for(int i = 0; i< GridView1.Rows.Count; i ++)
{
chb =(CheckBox)GridView1.Rows [i] .FindControl(chkStatus);
if(chb! = null)
{
values [i] = chb.Checked;
count ++;
}
}
会话[page+ GridView1.PageI ndex] =值;
GridView1.PageIndex = e.NewPageIndex;
DataTable dtPagination =((DataTable)Session [details]);
DataView dvPagination = new DataView(dtPagination) ;
GridView1.DataSource = dtPagination;
GridView1.DataBind();
}
i使用这两个事件我可以查看分页中的复选框但我想知道我用分页控件检查了整体gridview的复选框有多少.....
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
Response.Write(GridView1.PageIndex.ToString());
int d = GridView1.PageCount;
bool[] values = new bool[GridView1.PageSize];
CheckBox chb;
int count = Convert.ToInt32(ViewState["total"]);
for (int i = 0; i < GridView1.Rows.Count; i++)
{
chb = (CheckBox)GridView1.Rows[i].FindControl("chkStatus");
if (chb != null)
{
values[i] = chb.Checked;
count++;
}
}
Session["page" + GridView1.PageIndex] = values;
GridView1.PageIndex = e.NewPageIndex;
DataTable dtPagination = ((DataTable)Session["details"]);
DataView dvPagination = new DataView(dtPagination);
GridView1.DataSource = dtPagination;
GridView1.DataBind();
}
i have use these two events i can check the checkbox in the paging but i want to know how many check boxes i have checked overall gridview with paging control.....
维护一个检查到会话变量的复选框计数器。对于每个选中和未选中的复选框,应更新此会话变量。
编辑:
在checkbox_checked服务器端的事件,更新会话变量中维护的计数器。选中未选中的每个复选框都会触发此事件。
Maintain a counter of checkboxes checked into a session variable. This session variable should be updated for every checkbox checked and unchecked.
On the checkbox_checked event on server side , update the counter maintained in the session variable. This event is fired on every checkbox checked-unchecked.
这篇关于在GridView控件中进行分页时CheckBox的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!