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事件中处理 --------------------编程问答--------------------
--------------------编程问答-------------------- 正解 --------------------编程问答-------------------- 你确定string uname_temp = GridView1.Rows[i].Cells[1].Text;
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