首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

关于datalist控件中linkbutton的屏蔽有关问题

2013-09-09 
关于datalist控件中linkbutton的屏蔽问题最近分页用了AspNetPager控件,感觉蛮好用的,但是用完后就出现一个

关于datalist控件中linkbutton的屏蔽问题
最近分页用了AspNetPager控件,感觉蛮好用的,但是用完后就出现一个问题,我之前写的关于datalist中linkbutton控件根据权限等级来实现是否屏蔽的功能一点用都没有了,调试也能进的,如果我换成以前写的分页方法,就能正常的实现功能。希望大家帮我看下怎么回事,现在弄的有点莫名其妙的。。=w=

这是我未更改前的

 public partial class Check : System.Web.UI.Page
    {
        AnwerbeformularTable user = new AnwerbeformularTable();

        sys_UserPermission P = new sys_UserPermission();
        sys_AnwerbeformularDateTable Date = new sys_AnwerbeformularDateTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindUserList();
                ddlBind();
            }
            if (Session["UserID"] != null)
            {
                this.HiUserID.Value = Session["UserID"].ToString();

            }
            else
            {
                Response.Redirect("/Manager/LoginOut.aspx");
            }
            HiDepartmentID.Visible = false;
            HiPositionID.Visible = false;
            HiInCharge.Visible = false;
            HiHR.Visible = false;
            HiUserID.Visible = false;
            HiLv.Visible = false;

            using (SqlConnection con1 = new SqlConnection(ConfigurationManager.AppSettings["MsSql"]))


            {
                con1.Open();

                string sqlStr = "select  Lv FROM sys_UserPermission where UserID ='" + HiUserID.Value + "'  ";
                SqlCommand com = new SqlCommand(sqlStr, con1);
                SqlDataReader dr = com.ExecuteReader();
                while (dr.Read())
                {
                    HiLv.Value = Convert.ToString(dr.GetInt32(0));
                }
                con1.Close();
            }

            for (int i = 0; i < UserList.Items.Count; i++)
            {
                if (HiLv.Value == "1")
                {
                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifCEO")).Enabled = false;
                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifHR")).Enabled = false;
                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifInCharge")).Enabled = false;
                }
                else if (HiLv.Value == "2")
                {

                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifCEO")).Enabled = false;


                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifHR")).Enabled = false;
                }
                else if (HiLv.Value == "3")
                {
                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifInCharge")).Enabled = false;
                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifHR")).Enabled = false;
                }
                else if (HiLv.Value == "4")
                {
                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifInCharge")).Enabled = false;
                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifCEO")).Enabled = false;
                }
                else if (HiLv.Value == "5")
                {
                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifCEO")).Enabled = true;
                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifHR")).Enabled = true;
                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifInCharge")).Enabled = true;
                }
                else
                {


                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifCEO")).Enabled = false;
                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifHR")).Enabled = false;
                    ((LinkButton)UserList.Items[i].FindControl("lkbtnModifInCharge")).Enabled = false;
                }
            }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindUserList();
        }

       //UserList数据绑定
        public void BindUserList()
        {
            PagedDataSource ps = new PagedDataSource();
            ps.DataSource = Anwerbeformularbll.GetAnwerbeformular();

            this.AspNetPager1.RecordCount = Int32.Parse(ps.Count.ToString());
            int pageIndex = this.AspNetPager1.CurrentPageIndex - 1;
            int pageSize = this.AspNetPager1.PageSize = 15;
            ps.AllowPaging = true;
            ps.PageSize = pageSize;
            ps.CurrentPageIndex = pageIndex;

            UserList.DataSource = ps;

            UserList.DataBind();
        }

        private void BindUserList()
        {
            //int cup = Convert.ToInt32(this.lb_CurrentPage.Text);


            PagedDataSource ps = new PagedDataSource();
            ps.DataSource = Anwerbeformularbll.GetAnwerbeformular();
            ps.AllowPaging = true; ps.PageSize = 10;
            //每页显示的数据的行数         
            //ps.CurrentPageIndex = cup - 1;
            //lb_count.Text = ps.DataSourceCount.ToString(); //获取记录总数         
            //lb_page.Text = ps.PageCount.ToString(); //获取总页数




            int CurPage;
            if (Request.QueryString["Page"] != null && Request.QueryString["Page"] != "0")
            {
                CurPage = Convert.ToInt32(Request.QueryString["Page"]);
            }
            else
            {
                CurPage = 1;
            }


            ps.CurrentPageIndex = CurPage - 1;
            int Counts = ps.PageCount;
            labPage.Text = "共 " + Counts.ToString() + " 页";
            if (!ps.IsFirstPage && !ps.IsLastPage)
            {
                first.Visible = true;
                first.Enabled = true;
                last.Visible = true;


                last.Enabled = true;
                next.Visible = true;
                next.Enabled = true;
                up.Visible = true;
                up.Enabled = true;
                this.first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";
                this.last.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(Counts);
                up.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
                next.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
                lb_Currentpage.Text = CurPage.ToString();
            }
            else if (!ps.IsFirstPage && ps.IsLastPage)
            {
                last.Visible = false;
                last.Enabled = false;
                up.Visible = true;
                up.Enabled = true;
                next.Visible = false;
                next.Enabled = false;

                this.first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";
                up.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);


                lb_Currentpage.Text = CurPage.ToString();
            }
            else if (ps.IsFirstPage && !ps.IsLastPage)
            {
                first.Visible = false;
                first.Enabled = false;
                next.Visible = true;
                next.Enabled = true;
                up.Visible = false;
                up.Enabled = false;
                this.last.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(Counts);
                next.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
                lb_Currentpage.Text = CurPage.ToString();
            }
            else
            {
                first.Visible = false;
                first.Enabled = false;
                next.Visible = false;
                next.Enabled = false;
                up.Visible = false;
                up.Enabled = false;
                last.Visible = false;
                last.Enabled = false;


            }

            UserList.DataSource = ps;

            UserList.DataBind();

        }



我更改后的(就这边变了下)
 protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindUserList();
        }

        //UserList数据绑定
        public void BindUserList()
        {
            PagedDataSource ps = new PagedDataSource();
            ps.DataSource = Anwerbeformularbll.GetAnwerbeformular();

            this.AspNetPager1.RecordCount = Int32.Parse(ps.Count.ToString());
            int pageIndex = this.AspNetPager1.CurrentPageIndex - 1;
            int pageSize = this.AspNetPager1.PageSize = 15;
            ps.AllowPaging = true;
            ps.PageSize = pageSize;
            ps.CurrentPageIndex = pageIndex;

            UserList.DataSource = ps;

            UserList.DataBind();
        }

想问下为什么执行出来效果不一样
[解决办法]
查看源代码看一下linkbutton的id是不是变了
[解决办法]
datalist的clientidmode="Static"试试

热点排行