获取不到Repeater控件中的CheckBox选中状态
写在前面的话:在做一个项目的时候,需要使用到Repeater控件,并且在Repeater控件内放置了CheckBox控件来标志需要删除的行,选中后,在后台取到的CheckBox的值总是为false。最后发现是在PageLoad函数中没有判断是否是回发就绑定了Repeater控件的数据,那么每次进入页面CheckBox控件的值当然被刷新为false了。
前台页面:
<div class="contianer p10">
<h3>
当前位置:<a href="Index.aspx" target="_self" >首页</a>>文章管理</h3>
<hr/>
<div class="content">
<asp:repeater ID="rptArticle" runat="server" ClientIDMode="Static" >
<HeaderTemplate>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<th width="6%">选择</th>
<th width="6%">编号</th>
<th align="left">文章标题</th>
<th width="16%">发布时间</th>
<th width="10%">操作</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:CheckBox ID="cb_id" CssClass="checkall" runat="server" /></td>
<td><asp:Label ID="lb_id" runat="server" Text='<%#Eval("aNo")%>'></asp:Label></td>
<td><a href="ArticleShow.aspx?id=<%#Eval("aNo") %>"><%#Eval("aTitle")%></a></td>
<td><%#string.Format("{0:g}", Eval("aDate"))%></td>
<td><span><a href="ArticleShow.aspx?id=<%#Eval("aNo") %>">修改</a></span></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>
</div>
<div class="clear"></div>
<!-- 分页控件 -->
<div>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" HorizontalAlign="Right" ShowCustomInfoSection="Right"
Width="100%" Style="font-size: 12px" inputboxstyle="width:19px" CustomInfoHTML=""
ShowPageIndexBox="Always" AlwaysShow="false" FirstPageText="首页" LastPageText="尾页"
NextPageText="下一页" PrevPageText="上一页" CustomInfoStyle="FONT-SIZE: 12px" CurrentPageButtonClass="pagination"
PageSize="16" ForeColor="#1460AD" OnPageChanged="AspNetPager1_PageChanged">
</webdiyer:AspNetPager>
</div>
<!-- 分页控件end --> <br />
<asp:Button ID="BtnDelete" runat="server"
OnClientClick="return confirm( '确定要删除这些记录吗? ');"
onclick="BtnDelete_Click" Text="删除" />
<asp:Label ID="lbMsg" runat="server" Text=""></asp:Label>
<asp:Button ID="BtnAdd" runat="server" Text="添加"
onclick="BtnAdd_Click"/> </div>
后台页面:
ArticleBLL bll = new ArticleBLL();
protected void Page_Load(object sender, EventArgs e)
{
this.lbMsg.Text = "";
if (!IsPostBack)
{
BindRepeater();
}
}
// 绑定数据
private void BindRepeater()
{
string strSql = "select * from article"; PagedDataSource ps = new PagedDataSource();
ps.DataSource = bll.GetDataList(strSql).DefaultView;
AspNetPager1.RecordCount = ps.Count;
ps.CurrentPageIndex = AspNetPager1.CurrentPageIndex - ;
ps.AllowPaging = true;
ps.PageSize = AspNetPager1.PageSize;
this.rptArticle.DataSource = ps;
this.rptArticle.DataBind();
}
// 分页控件事件绑定
public void AspNetPager1_PageChanged(object sender, EventArgs e)
{
BindRepeater();
}
// 添加文章
protected void BtnAdd_Click(object sender, EventArgs e)
{
Response.Redirect("ArticleShow.aspx");
}
// 删除
protected void BtnDelete_Click(object sender, EventArgs e)
{
for (int i = ; i < rptArticle.Items.Count; i++)
{
int id = Convert.ToInt32(((Label)rptArticle.Items[i].FindControl("lb_id")).Text);
CheckBox cb = (CheckBox)rptArticle.Items[i].FindControl("cb_id");
if (cb.Checked)
{
bll.Delete(id.ToString());
}
}
this.lbMsg.Text = "删除成功";
}
处理办法是在PageLoad里面判断是否是回发就可以了。
获取不到Repeater控件中的CheckBox选中状态的更多相关文章
- asp.net关于Repeater控件中的全选,批量操作
今天在Repeater控件中碰到一个全选的操作,于是上网查了一下,找到一个觉得比较好,便记录下来, 界面代码简化之后(全选操作): <script type="text/javascr ...
- 在Repeater控件中使用if语句
原文:在Repeater控件中使用if语句 .Afr_ARTICLE_TITLE { font: NORMAL BOLD 14px "Tahoma"; } .Afr_CONTENT ...
- 获取Repeater控件中的每一项数据
var items = rptList.Items;//获取Repeater控件的所有项 foreach (RepeaterItem item in items)//遍历每一项内容 { var t ...
- ASP.NET- 查找Repeater控件中嵌套的控件
如何在Repeater的HeaderTemplate和FooterTemplate模板中寻找控件?在Repeater的ItemTemplate模板中的控件,我们可以用Items属性来遍历行并用Find ...
- asp.net 在repeater控件中加按钮
在repeater中加入方法有两种方法: 第一种:是对repeater控件的行添加OnItemCommand事件,添加方法也是有两种 1.在设计页面中,选中repeater控件右击==>属性== ...
- JQuery获取指定元素中的checkbox选中状态的一些属性
项目中用户上传病例数据,每一次上传自动生成一个病例文件夹,数据保存到后台,前端显示文件夹,现在的需求是勾选想要删除的文件夹的chenckbox,点击删除后,数据库和前端都相应的更新. 如果是静态页面, ...
- Repeater控件中的三目运算
<asp:Repeater ID="rptimg" runat="server"> <ItemTemplate> ...
- 获取WPF的DataGrid控件中,是否存在没有通过错误验证的Cell
/// <summary> /// 获取DataGrid的所有行是否存在验证错误. /// </summary> /// &l ...
- Repeater控件中的LinkButton(转)
LinkButton小用法: 1.在使用时可以通过CommandName和CommandArgument属性联合起来绑定并传值,如:CommandName="record"Comm ...
随机推荐
- 1z0-052 q209_2
2: View the Exhibit to examine the output produced by the following query at three different times s ...
- 关于python打包成exe的一点经验之谈
我经常用python写些脚本什么的,有时候脚本写完以后,每次运行都得在IDE打开在运行,很麻烦,所以经常将python编译成exe.SO...有了一点经验,在这和大家分享一下. python ...
- EXCEPTION-TOMCAT
CreateTime--2016年10月24日16:22:12Author:Marydon声明:异常类文章主要是记录了我遇到的异常信息及解决方案,解决方案大部分都是百度解决的,(这里只是针对我遇到 ...
- SettingsSVNPlugin
迁移时间:2017年5月20日11:24:50CreateTime--2016年9月18日17:53:20Author:Marydonmyeclipse/eclipse中配置svn插件参考链接:h ...
- 〖Android〗酷派手机固件.cpb文件的分解程序
/* * ===================================================================================== * * Filen ...
- SET GLOBAL FOREIGN_KEY_CHECKS取消外键约束
今天在工作中遇到的问题,在删除一个表时报错,发现有外键约束,所以不能删除,查了下发现需要取消外键约束. SET GLOBAL FOREIGN_KEY_CHECKS=0;全局取消外键约束 SET SES ...
- echo “新密码”|passwd --stdin 用户名
--stdin This option is used to indicate that passwd should read the new password from standard input ...
- Rational Rose 2003 逆向工程转换C++源代码成UML类图
主要介绍用户如何使用Rose的逆向工程生成UML模型,并用来进行C++代码的结构分析. Rational Rose可以支持标准C++和Visual C++的模型到代码的转换以及逆向工程.下面将详细地说 ...
- Windows I/O完成端口
内容: 1.基本概念 2.WINDOWS完成端口的特点 3.完成端口(Completion Ports )相关数据结构和创建 4.完成端口线程的工作原理 5.Windo ...
- 如何在Win8中设置虚拟热点共享上网(转)
摘自:http://www.enet.com.cn/article/2013/0408/A20130408273749.shtml 在Windows 7中,我们可以通过网络与共享中心的“设置新的连接和 ...