ASP.NET2.0(C#) 开发WebForm请教关于GridView的两个问题:
1、 protected void GV_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[4].ToolTip = e.Row.Cells[5].Text;
        }
    }
如果e.Row.Cells[5].Text值为空,那么显示标签提示的时候就显示为“ ”。有没有办法把“ ”去掉啊?2、GridView自带的“编辑”按钮,通过该按钮对GridView里面的数据进行修改的时候,可修改的单元格会变成一个“TextBox”,有什么办法可以控制“TextBox”的长度?请给出具体的代码,谢谢!学习,关注……

解决方案 »

  1.   

    1.
    string i = e.Row.Cells[5].Text;
    if(e.Row.Cells[5].Text.Lenght == 0)
    {
      i = e.Row.Cells[5].Text.Replace(" ", " ");
    }
      

  2.   

    protected void GV_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[4].ToolTip = e.Row.Cells[5].Text;
                if(e.Row.Cells[4].ToolTip .Trim()=="")
                 {e.Row.Cells[4].ToolTip ="";}
            }
        }
      

  3.   

    楼主的说明:2、我以前使用DataGrid的时候,可以用代码来控制“TextBox”的长度的。写在ItemDataBound里面。在GridView中难道不能用代码来控制“TextBox”的长度???关注……
      

  4.   

    那就写在RowDataBound里呗,和DataGrid的ItemDataBound是一样的
      

  5.   

    楼主的说明:2、关键是DataGrid中可以使用的代码,到了GridView中就没有用了能否给出代码啊???关注……
      

  6.   

    代码控制protected void GV_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
               ((TextBox)e.Row.FindControl("TextBox1")).width=100px;       }
        }
      

  7.   

    不用写代码呀.选择Gridview的快捷菜单里的"编辑列",然后对你每一列设置其各个样式.一般是controlstyle和itemstyle.你可以在这里面控制编辑时文本控件的宽度和位置等等