**使用CheckBox在Gridview中选择数据。*** [英] ** Select Datas in Gridview using CheckBox.***
问题描述
嗨朋友们,
我有两页search.aspx& View.aspx。
Search.aspx包含一个带有Name,College,DepartMent列的网格视图>
选择 NAME 大学 部门
CBox AAAAA BBBBB CCCCC
CBox BBBBB CCCCC DDDDD
CBox CCCCC AAAAA DDDDD
< button text =transfer>< / button>
我的View.aspx页面
姓名:lblname
学院:lblcollege
系:lbldepartment
如果我选中了search.aspxgridview中的所有复选框并单击了转移按钮
,则所选值将移至View.aspx。 />
i需要结果如
名称:AAAAA, BBBBB,CCCCC
学院:BBBBB,CCCCC,AAAAA
部门:CCCCC,AAAAA,DDDDD
是这可能吗?
请帮帮我..
Hi friends,
i've two pages "search.aspx" & "View.aspx".
Search.aspx contains one gridview with columns "Name, College","DepartMent"
Select NAME COLLEGE DEPARTMENT
CBox AAAAA BBBBB CCCCC
CBox BBBBB CCCCC DDDDD
CBox CCCCC AAAAA DDDDD
<button text="transfer"></button>
my View.aspx Page Here
Name : lblname
College: lblcollege
Department: lbldepartment
If i've selected all the checkbox in "search.aspx" gridview and clicked the transfer button
then the selected values will move to "View.aspx".
i need a result like
Name : AAAAA , BBBBB , CCCCC
College : BBBBB , CCCCC , AAAAA
Department: CCCCC , AAAAA , DDDDD
is this possible??
please help me..
推荐答案
绝对可能。首先,您将数据绑定到Page_Load事件上的gridview,如下所示:
Absolutely possible. First you bind your data to gridview on Page_Load Event as follows:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Bind your gridview here.
}
}
现在你有四个gridview列NAME,COLLEGE,DEPARTMENT和一个复选框(我假设)
点击某个按钮的事件,声明数据表,遍历所有行并将检查的行添加到数据表,将它绑定到gridview。
Now you have gridview with four columns NAME,COLLEGE,DEPARTMENT and a checkbox(i assume)
On click event of some button,declare datatable,loop through all the rows and add checked rows to datatable,bind that to gridview.
DataTable dtable = new DataTable();
dtable.Columns.Add(new DataColumn("NAME", typeof(string)));
dtable.Columns.Add(new DataColumn("COLLEGE", typeof(string)));
dtable.Columns.Add(new DataColumn("DEPARTMENT ", typeof(string)));
Session["dt"] = dtable;
foreach (GridViewRow gvrow in yourgridview.Rows)
{
dtable = (DataTable)Session["dt"];
CheckBox chk = (CheckBox)gvrow.Cells[3].FindControl("CheckBox1");
if (chk != null && chk.Checked)
{ DataRow dd = dtable.NewRow();
dd["NAME"] = (gvrow.Cells[0].Text);
dd["COLLEGE"] = (gvrow.Cells[1].Text);
dd["DEPARTMENT "] = (gvrow.Cells[2].Text);
dtable.Rows.Add(dd);
GridView1.DataSource = dtable;
GridView1.DataBind();
}
}
//Here you got the complete list of data(GridView1) which has checkbox checked
将此gridview发送到适当的页面。
快乐编码.. :)
Send this gridview to appropriate page.
Happy coding.. :)
You create New Div and Create this
Name : AAAAA , BBBBB , CCCCC
College : BBBBB , CCCCC , AAAAA
Department: CCCCC , AAAAA , DDDDD
点击搜索按钮后这个div是真实的和
查看页面潜水是可见的错误所以你的问题解决了
and after click search button this div are visible true and
view page dive are visible false so your problem solve
我试过这个...但不满意。
I've Tried this one.. but not satisfied.
protected void lbassettransfer_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvrow in GridView1.Rows)
{
CheckBox chkdelete = (CheckBox)gvrow.FindControl("cbselect");
if (chkdelete.Checked)
{
int ID= Convert.Toint32(GridView1.DataKeys[gvrow.RowIndex].Value);
ViewState["ID"]=ID;
ds = objbal.GetSelectedData(ID);
Session["GETDATASET"] = ds;
}
}
}
这篇关于**使用CheckBox在Gridview中选择数据。***的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!