repeater问题
aspx:
<form method= "post " runat= "server " ID= "form1 ">
<table width= '85% ' border= '0 ' cellspacing= '0 ' cellpadding= '0 '>
<tr>
<td height= '24 ' align= 'right ' colspan=3> <font color= "#426402 ">
<asp:HyperLink ID= "newlink " runat= "server " NavigateUrl= "app.aspx " Target= "_self " Text= "新建 " ToolTip= "新建申请品种信息 "> </asp:HyperLink>
| <asp:LinkButton ID= "delLink " Text= "删除 " runat= "server "> </asp:LinkButton> </font>
</td>
<asp:repeater id= "vList " enableviewstate= "False " runat= "server ">
<headertemplate>
</tr>
<tr bgcolor= "#B1EFBB ">
<td width= "5% "> <input type= "CheckBox " id= "chk " onclick= "checkall(this); ">
</td>
<td> 编号 </td>
<td> 暂定名称 </td>
<td> 申请日期 </td>
</tr>
</headertemplate>
<itemtemplate>
<tr>
<td> <asp:CheckBox id= "sel " runat= "server "> </asp:CheckBox> </td>
<td> <a href= "vcenter.aspx?no= <%# DataBinder.Eval(Container.DataItem, "appno ")%> " target= "_self "> <%# DataBinder.Eval(Container.DataItem, "appno ")%> </a> </td>
<td> <%# DataBinder.Eval(Container.DataItem, "vname ")%> </td>
<td> <%# DataBinder.Eval(Container.DataItem, "appdate ")%> </td>
</tr>
</itemtemplate>
<footertemplate>
</footertemplate>
</asp:repeater>
</table>
<asp:Label Text= " <br> ok <br> ! " id= "Err_message " style= "color:Red; " visible=false runat= "server "/>
</form>
cs中:
protected void Page_Load(object sender, EventArgs e)
{
dbHandle=new CAdoHandle(this);
if(!IsPostBack)
{
BindPagedData();
for(int i=0;i <vList.Items.Count;i++)
{
CheckBox chk=(CheckBox)vList.Items[i].FindControl( "sel ");
chk.Attributes.Add( "onclick ", "uncheck(this); ");
}
}
}
protected void delLink_Click(object sender,EventArgs e)
{
string msg=null;
msg=vList.Items.Count.ToString();
for(int i=0;i <vList.Items.Count;i++)
{
CheckBox chk=(CheckBox)vList.Items[i].FindControl( "sel ");
if(chk.Checked==true)
{
string appno=((DataBoundLiteralControl)vList.Items[i].Controls[1]).Text;
if(msg== " ")
msg=appno;
else
msg=msg+ "; "+appno;
}
}
Err_message.Text= " <br> <br> aoono: "+msg+ " <br> ";
Err_message.Visible=true;
}
问题:
repeater在page_load时已经从数据库里取出若干记录并显示,可是执行delLink_Click时,vList.Item.Count却是0,哪里出了问题,大伙帮看看?!
[解决办法]
应该是禁用视图状态引起的问题,把 <asp:repeater id= "vList " enableviewstate= "False " runat= "server "> 这句中的enableviewstate= "False "去掉或设为true再试试。
===========================================
http://www.dotneturls.com/gb.aspx —.net开发资源精华收集,正在不断更新及完善中,欢迎推荐资源并提出意见和建议!
[解决办法]
修改如下,试试:
protected void delLink_Click(object sender,EventArgs e)
{
string msg=vList.Items.Count.ToString();
for(int i=0;i <vList.Items.Count;i++)
{
CheckBox chk=(CheckBox)vList.Items[i].FindControl( "sel ");
if(chk.Checked==true)
{
string appno=((DataBoundLiteralControl)vList.Items[i].Controls[1]).Text;
if(msg== " ")
msg=appno;
else
msg=msg+ "; "+appno;
}
}
Err_message.Text= " <br> <br> aoono: "+msg+ " <br> ";
Err_message.Visible=true;
BindPagedData(); //添加一句代码,再次绑定数据
}
[解决办法]
问题基本解决了,但还是有一事不明白,按了 "删除 "后,将记录前大勾的记录删除了,可是函数返回后页面显示的还是原来的记录,只有当重新进入该页时才显示删除后剩下的记录
========================
删除操作后要重新绑定数据啊