在datagrid中的摸板列有一个button, 请问在datagrid绑定数据的时候,怎样依据某一项的值控制button的Enabled属性啊?
比如说有一列是"状态",当"状态"="故障"时,button的enabled为true,否则为false.
哪位大侠帮帮忙呀?
在datagrid中的摸板列有一个button, 请问在datagrid绑定数据的时候,怎样依据某一项的值控制button的Enabled属性啊?
比如说有一列是"状态",当"状态"="故障"时,button的enabled为true,否则为false.
哪位大侠帮帮忙呀?
 2007-10-03 22:39
	    2007-10-03 22:39
  可以写在
protected void datagrid1_RowDataBound(object sender, GridViewRowEventArgs e)
  try
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {             
                    if (Convert.ToInt32(e.Row.Cells[8].Text.ToString().Trim()) > 0)
                    {
                        e.Row.Cells[1].ForeColor = Color.Red;                                      }
                }
            }
            catch
            { }
你可以看看这个代码 可能对了有帮助
 对了你要获得模板的button要用这个函数e.Row.FindControl()

 2007-10-04 08:02
	    2007-10-04 08:02
   2007-10-04 22:13
	    2007-10-04 22:13
  在DataSet里边可以控制
for(int i=0;i<DataSet.Tables["TB_name"].Rows.Count;i++)
{
if(DataSet.Tables["TB_name"].Rows[i]["状态"]="故障")
DataGridItem theItem=DataGrid.Items[(int)i];
Button btn=(Button)theItem.FindControl("你定义的Button_ID");
btn.Enabled=false;
}
如果你实在不办法的话,可以试一下这个..

 2007-10-04 23:12
	    2007-10-04 23:12
  我按照这个方法好象不行啊,执行到这一步 
DataGridItem theItem=DataGrid.Items[(int)i]; 
就出错了,"索引超出范围............参数名:index"
我太菜了~ 能不能把详细步骤写一下啊~
 能不能把详细步骤写一下啊~
 
 2007-10-05 14:57
	    2007-10-05 14:57
  搞定了,可以在ItemDataBound里面做个判断,谢谢大家了~
 2007-10-05 18:49
	    2007-10-05 18:49