在DataGrid中有(名称及选择两列,其中“选择”是按钮列),填充数据后,我又加了几条空行凑够15条记录,使得看上去好看些,加完后,空行是不显示任何信息的,包括“选择”这一列,运行后点击有数据行的“选择”后,之前添加的空行中“选择”列出现“选择”两个字了,现在我要问你怎么去掉空行显示的“选择”?

解决方案 »

  1.   

    后台进行判断再添加.在ItemCreated事件中:
    if(不是空行)
    {
      Button myButton = new Button();
      myButton.ID = "btnAddNew";
      myButton.Text = "选择";
      myButton.CommandName = "select";
      e.Cell[1].Controls.Add(myButton);
    }
      

  2.   

    一楼的方法可行,
    ItemDataBound事件中
    if(!e.Item.Cells[0].Text.Equals(string.Empty))
    {
    Button myButton = new Button();
      myButton.ID = "btnAddNew";
      myButton.Text = "选择";
      myButton.CommandName = "select";
      e.Cell[1].Controls.Add(myButton);}
      

  3.   

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(!e.Item.Cells[0].Text.Equals(string.Empty))
    {
    Button myButton = new Button();
    myButton.ID = "btnAddNew";
    myButton.Text = "选择";
    myButton.CommandName = "select";
    e.Cell[1].Controls.Add(myButton);

    }
    出错:C:\Inetpub\wwwroot\GWLL\MaterialUse.aspx.cs(256): “System.Web.UI.WebControls.DataGridItemEventArgs”并不包含对“Cell”的定义
      

  4.   

    e.Cell[1].Controls.Add(myButton);
    应该写成e.Item.Cells[1].Controls.Add(myButton); 吧!
      

  5.   

    我觉得将其设定为不显示好点,方法如下,你们认为呢?
    在ItemCreated事件中:
    if(不是空行)
    {
    ((LinkButton)e.Item.Cells[1].Controls[0]).Visible=false;}
      

  6.   

    Sorry,刚没看清楚,LinkButton要改为Buttonif(!e.Item.Cells[0].Text.Equals(string.Empty))
    {
    ((Button)e.Item.Cells[1].Controls[0]).Visible=false;}
      

  7.   

    另外因为机制不同
    代码要写在ItemDataBound事件里面.
    去吃饭了,88
      

  8.   

    我现在用了如下的:在ItemCreated事件中:
    if(!e.Item.Cells[0].Text.Equals(string.Empty))
    {
    ((LinkButton)e.Item.Cells[8].Controls[0]).Visible=false;}执行SQL语句出错:指定的参数已超出有效值的范围。参数名: index//总共有9个字段,第8个是"选择"列!
      

  9.   

    to LZ:
    1.将代码添加到在ItemCreated事件中:
    2,((LinkButton)e.Item.Cells[7].Controls[0]).Visible=false;//如果第8个是选择列的话
    如果不行的话直接发代码我给你改