就是 留言的 删除回复功能问题,我想这样做 判断管理员是否登录 如果管理员登录了 删除和回复按键 才能显示出来 如果管理员未登录 者普通的访问留言板 是看不到 删除和回复按键的 我弄了好几次都弄不对.....错误提示:
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS0117: “index”并不包含“lbtnDelete”的定义源错误: 行 17: if (Session["admin"] != null)
行 18: {
行 19: this.lbtnDelete.Visible=false ;
行 20: }
行 21: this.datalist();代码是这样写的
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["admin"] != null)
{
this.lbtnDelete.Visible=false ;
}
this.datalist();
}
protected void datalist()
{
SqlConnection con = DB.createCon();
con.Open();
SqlDataAdapter sda=new SqlDataAdapter ();
sda.SelectCommand = new SqlCommand("select * from lyb order by uid desc", con);
DataSet ds = new DataSet();
sda.Fill(ds, "liu");
this.DataList1.DataSource = ds.Tables["liu"];
this.DataList1.DataBind();
}
protected void lbtnReply_Command1(object sender, CommandEventArgs e)
{
if (Session["admin"] != null)
{
string userID = e.CommandArgument.ToString();
Response.Redirect("reply.aspx?userID=" + userID + "");
}
else
{
Response.Write("<script>alert('对不起,只有管理员才允许回复留言,如果你是管理员,请先登陆!');window.location.href='login.aspx';</script>");
}
}
protected void lbtnDelete_Command(object sender, CommandEventArgs e)
{
if (Session["admin"] != null)
{
//string userID = e.CommandArgument.ToString();
string userID = e.CommandArgument.ToString();
SqlConnection con = DB.createCon();
con.Open();
SqlCommand cmd = new SqlCommand("delete from lyb where uid='" + userID + "'", con);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('对不起,只有管理员才允许删除留言,如果你是管理员,请先登陆!');window.location.href='login.aspx';</script>");
Response.Write("<script>alert('删除成功!');window.location=window.location;</script>");
}
}
}
忘前辈 指教!谢谢啦
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS0117: “index”并不包含“lbtnDelete”的定义源错误: 行 17: if (Session["admin"] != null)
行 18: {
行 19: this.lbtnDelete.Visible=false ;
行 20: }
行 21: this.datalist();代码是这样写的
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["admin"] != null)
{
this.lbtnDelete.Visible=false ;
}
this.datalist();
}
protected void datalist()
{
SqlConnection con = DB.createCon();
con.Open();
SqlDataAdapter sda=new SqlDataAdapter ();
sda.SelectCommand = new SqlCommand("select * from lyb order by uid desc", con);
DataSet ds = new DataSet();
sda.Fill(ds, "liu");
this.DataList1.DataSource = ds.Tables["liu"];
this.DataList1.DataBind();
}
protected void lbtnReply_Command1(object sender, CommandEventArgs e)
{
if (Session["admin"] != null)
{
string userID = e.CommandArgument.ToString();
Response.Redirect("reply.aspx?userID=" + userID + "");
}
else
{
Response.Write("<script>alert('对不起,只有管理员才允许回复留言,如果你是管理员,请先登陆!');window.location.href='login.aspx';</script>");
}
}
protected void lbtnDelete_Command(object sender, CommandEventArgs e)
{
if (Session["admin"] != null)
{
//string userID = e.CommandArgument.ToString();
string userID = e.CommandArgument.ToString();
SqlConnection con = DB.createCon();
con.Open();
SqlCommand cmd = new SqlCommand("delete from lyb where uid='" + userID + "'", con);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('对不起,只有管理员才允许删除留言,如果你是管理员,请先登陆!');window.location.href='login.aspx';</script>");
Response.Write("<script>alert('删除成功!');window.location=window.location;</script>");
}
}
}
忘前辈 指教!谢谢啦
解决方案 »
- 页面间传递List<T> t 泛型数组
- ****正则表达式(50分)
- 散分了,给个思路啊(100分)
- 请求帮助,想实现一个图片显示功能.(高分)
- 大型新闻网站的首页中一行可以显示多条新闻标题,是如何实现的?
- 急聘.NET(c#)项目经理(杭州,高薪)
- 如何让当前获得焦点的控件背景显示为淡兰色?失去焦点又恢复白色?
- 客户的邮件系统比较慢,如何在发送邮件后就返回,避免等待。。。
- asp.net 用网页的形式显示office或者pdf文档
- .NET技术交流资源共享-------------群------------7991387一起学习一起进步!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 请教关于创建web页面的问题
- 如何为取key
你判断页面的 session身份是否为 管理员 是就 his.lbtnDelete.Visible=true;
不是就his.lbtnDelete.Visible=false ;
Session["admin"] =账户ID
那么这时候你可以判断Session["admin"]是否等于管理员ID。
如果可能拥有这个权限的账户不唯一 也可以在登录的时候 查询其是否属于管理员的角色 有 就在Session里存储个值 用到以后的权限判断 怎么设定就看你怎么去设计系统权限了
this.lbtnDelete.Visible=Session["admin"] == null?false:true;
datalist可使用Visible="<%# GetVisible() %>获取
public bool GetVisible()
{
return Session["admin"] == null?false:true;
}或findcontrol查找控件设置visible
{
this.lbtnDelete.Visible=false ;
}
貌似你弄反了,你不是要管理员登录就显示么,怎么false了
如果是这样的话,你是不能这样用的。