我要在gridview中的模板列中加入一个退房的button,条件是如果已经退房了,就不在gridview上面显示,如果没有退房的话,就在上面显示。
请问怎么实现这个功能啊?

解决方案 »

  1.   

    在gridview的中加个button,在databinging中判断是否退房,如果退了button的visible为false,反之为true
      

  2.   

    在邦定数据的时候进行判断
    void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //throw new Exception("The method or operation is not implemented.");
            if(e.Row.RowType == DataControlRowType.DataRow)
            {
                Button btn = e.Row.FindControl("buttonid") as Button;
    if("已经退房")
    {
    btn.Visible = false;
    }
    }
    }
      

  3.   

    怎么我点e.Row的时候说不包含row的定义啊?
      

  4.   

    错误 1 “System.Web.UI.WebControls.GridViewUpdatedEventArgs”不包含“Row”的定义,并且找不到可接受类型为“System.Web.UI.WebControls.GridViewUpdatedEventArgs”的第一个参数的扩展方法“Row”(是否缺少 using 指令或程序集引用?) F:\MyFunCode\RoomList\RoomList\Index.aspx.cs 130 19 RoomList
      

  5.   

    GridView1.DataSource=dt;
    GridView1.DataBind();
    //后面加上
    for(int i=0;i<GridView1.Rows.Count;i++)
    {
       Button tn=(Button)GridView1.Rows[i].FindControl("退房按钮ID");
       if(dt.Rows[i]["退房列"].ToString()=="退房")
       {  
          tn.Visible=false;
       }
    }
      

  6.   


     GridViewRow gr = this.GridView1.Rows[GridView1.SelectedRow.RowIndex];
                Button btn = (Label)gr.FindControl("buttonID");这样就可以得到Button控件了
      

  7.   

       Button btn = (Label)gr.FindControl("buttonID"); 
    改为:
       Button btn = (Button)gr.FindControl("buttonID"); 
      

  8.   

    前台gridview中加:
     <asp:TemplateField HeaderText="删除"> 
     </asp:TemplateField> 
    后台: protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Label lbl_Del = new Label();
            //e.Row.Cells[7].Text添加你需要的那个状态,然后在 
        /* protected void myGridView_RowCreated(object sender, GridViewRowEventArgs e)
        {      
                    e.Row.Cells[7].Visible = false;
        }
        */
        不显示,但是可以每次读取数据库的状态,然后加载下面的代码
            if (e.Row.Cells[7].Text == "1")
           {
                 lbl_Del.Text = “<input type='Button' text='btn' >";
                 e.Row.Cells[n].Controls.Add(lbl_Del);       }
            不显示,但是可以每次读取数据库的状态,然后加载下面的代码
            if (e.Row.Cells[7].Text == "0")
           {
                 lbl_Del.Text = “<input type='XXXX' text='btn' >";
                 e.Row.Cells[n].Controls.Add(lbl_Del);       }             
    }
    看懂没?