请问在GridView中,如何实现CheckBox的选择后,翻页仍然有效

sunck 2009-03-10 10:45:18
就是在GridView页面的选择,向前向后翻动,都可以保持住原来checkBox的选择,希望有个成熟的做法
...全文
171 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
珺珺 2009-10-28
  • 打赏
  • 举报
回复
sunck ,你这方法真的可行吗?我试过怎么不行啊?
sunck 2009-03-11
  • 打赏
  • 举报
回复
在朋友的帮助下,这是我的解决方案,
添加2个textbox记录变量信息,在模板列的CheckBox事件中写程序,记录id等信息,在gridview的
RowDataBound事件中,把记录的信息反映到列中的checkbox,程序调试成功
protected void CheckBox_telecomm_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb1 = (CheckBox)sender;
if (cb1.Checked)
{
//if (LabelTelecommID.Text == "")
// LabelTelecommID.Text = cb1.Text;
//else
LabelTelecommID.Text = LabelTelecommID.Text + "^" + cb1.Text;
LabelTelecommCount.Text = Convert.ToString(Convert.ToInt16(LabelTelecommCount.Text) + 1);
}
else
{
LabelTelecommID.Text = LabelTelecommID.Text.Replace(cb1.Text, "");
LabelTelecommCount.Text = Convert.ToString(Convert.ToInt16(LabelTelecommCount.Text) - 1);
}

}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (LabelTelecommID.Text == "")
return;

foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = row.FindControl("CheckBox_telecomm") as CheckBox;

if (LabelTelecommID.Text.IndexOf(cb.Text) >= 0)
{
cb.Checked = true;
}

}
}
wuyq11 2009-03-10
  • 打赏
  • 举报
回复
通过模板列
<input type="checkbox" runat="server" id="chkSelect" onclick="AddValues(this)" value='<%#DataBinder.Eval(Container.DataItem,"XTBH")%>' title='<%#DataBinder.Eval(Container.DataItem,"ZT")%>' NAME="chkSelect"/>
function AddValues(oChk) {
if(oChk.checked)
{
var z=oChk.title;
Form1.Hd.value += "," + oChk.value;
Form1.HdZT.value+=","+z;
}
else
{
var z=oChk.title;
Form1.Hd.value = Form1.Hd.value.replace("," + oChk.value,"");
Form1.HdZT.value = Form1.HdZT.value.replace("," + z,"");
}
}
<INPUT id="Hd" type="hidden" name="Hd" runat="server"><INPUT id="HdZT" type="hidden" name="HdZT" runat="server">
实现保存
sunck 2009-03-10
  • 打赏
  • 举报
回复
使用TextBox作为保存是可以实现,但是假设翻页回去,取消已经按过的checkBox,这个就很难做了。另外我想问如何定位到当前页
liuyeede 2009-03-10
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20090310/02/bd11de6f-e475-41bf-8097-ad5ea04120c7.html
dafoweilin 2009-03-10
  • 打赏
  • 举报
回复
sunck 2009-03-10
  • 打赏
  • 举报
回复
虽然还没有测试,我觉得这个答案确实很牛

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧