当前位置:编程学习 > C#/ASP.NET >>

GridView绑定数据

.Net的GridView数据绑定后(GridView有did,dname,dedit这几列),要哪一行的dname是等于“xx”的,那么就让dedit.Enable=false,否则,就是true。请问这个怎么实现?
我写了如下的代码,但是,不知道为什么,uname_temp=“”,可是在页面上明明有数据的
  protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                ListBind();
            }
            string uname = Convert.ToString(Application.Get("UserName"));
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                int i_lastindex = GridView1.Columns.Count - 1;
                string uname_temp = GridView1.Rows[i].Cells[1].Text;
                if (uname_temp == uname)
                 {
                    GridView1.Rows[i].Cells[i_lastindex].Enabled = true;
                }
                else
                {
                    GridView1.Rows[i].Cells[i_lastindex].Enabled = false;
                }

            }
        } --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 在rowbound事件中处理 --------------------编程问答--------------------

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[1].Text == "xxx")
            {
                设置是否可编辑
            }
    }
--------------------编程问答--------------------
引用 3 楼 bdmh 的回复:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[1].Text == "xxx")
            {
                设置是否可编辑
            }
    }
正解 --------------------编程问答-------------------- 你确定string uname_temp = GridView1.Rows[i].Cells[1].Text;
你要提取的是第二列的值 --------------------编程问答--------------------
引用 3 楼 bdmh 的回复:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[1].Text == "xxx")
            {
                设置是否可编辑
            }
    }
+1
补充:.NET技术 ,  .NET Framework
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,