前台代码:
<asp:Label ID="lbl" Visible="True" Runat="server">
<%#DataBinder.Eval(Container.DataItem,"msgid")%>
</asp:Label>后台代码.
string SMsgId;
private void Rp2_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
sMsgId = ((Label)e.Item.FindControl("lbl")).Text.Trim();
if(e.CommandName=="delete")
{
string strSQL = "delete from msgtable where msgid='"+this.sMsgId+"'";
SqlCommand com=new SqlCommand(strSQL,MyConnection);
MyConnection.Open();
com.ExecuteNonQuery();
MyConnection.Close();
}
this.databindRp2();
}
这个值为什么获得不到?前台将Label显示,可以看见值!
<asp:Label ID="lbl" Visible="True" Runat="server">
<%#DataBinder.Eval(Container.DataItem,"msgid")%>
</asp:Label>后台代码.
string SMsgId;
private void Rp2_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
sMsgId = ((Label)e.Item.FindControl("lbl")).Text.Trim();
if(e.CommandName=="delete")
{
string strSQL = "delete from msgtable where msgid='"+this.sMsgId+"'";
SqlCommand com=new SqlCommand(strSQL,MyConnection);
MyConnection.Open();
com.ExecuteNonQuery();
MyConnection.Close();
}
this.databindRp2();
}
这个值为什么获得不到?前台将Label显示,可以看见值!
然后才帮定lable当然就查不到了
大小写
有没有+上!IsPostBack
估计是直接在load过程赋值了或进行了一些操作导致值丢失
另外就是看一下是否开启了viewstate
这样写
<asp:Label ID="lbl" Visible="True" Runat="server" Text="<%#DataBinder.Eval(Container.DataItem,"msgid")%>" ></asp:Label>
<%#DataBinder.Eval(Container.DataItem,"msgid")%>
</asp:Label>那个应该写到text属性里面吧