一个关于DATAGRID编辑的问题(自动生成TEXTOX,控制长度的问题),急!!!前台:
<asp:BoundColumn HeaderText="合同岗位" DataField="Htgw" ItemStyle-HorizontalAlign="Center" />后台:
放在Grid_Update事件中:
CType(e.Item.Cells(6).Controls(0), TextBox).Width = Unit.Pixel(150)
老是不能定义自动生成文本框的长度,谁帮我解决一下啥?

解决方案 »

  1.   

    你可能改为用模版列,就可以手工来定义TEXTBOX的长度了.
      

  2.   

    Grid_Update事件?试一下其他事件...
      

  3.   

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if( e.Item.ItemType == ListItemType.EditItem )
    {
    TextBox TB = ( TextBox )e.Item.Cells[6].Controls[0];
    TB.Width = 77;
    }
    }
      

  4.   

    晕死,我的就是这样的。'当鼠标经过单元格时改变颜色
        Sub MyGrid_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='lavender'")            If e.Item.ItemType = ListItemType.Item Then
                    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='ghostwhite'")                'Dim i As Integer
                    'For i = 0 To e.Item.Cells.Count - 1 Step i + 1
                    'Dim txt As TextBox = CType(e.Item.Cells(i).Controls(0), TextBox)
                    'txt.Width = Unit.Pixel(50)
                    'Next                'Dim txtDate_ZzText As TextBox = CType(e.Item.Cells(4).Controls(0), TextBox)
                    'txtDate_ZzText.Width = Unit.Pixel(50)
                    'txtDate_ZzText.Width = MyGrid.HeaderStyle.Width
                Else
                    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='ghostwhite'")
                End If            '删除确认弹出“确定”与“取消”对话框
                Dim btnDelete As LinkButton = CType(e.Item.Cells(10).Controls(0), LinkButton)
                btnDelete.Attributes.Add("onclick", "javascript:return confirm('确定删除吗?删除以后将无法恢复!');")        End If
    '删除确认弹出“确定”与“取消”对话框
                Dim btnDelete As LinkButton = CType(e.Item.Cells(10).Controls(0), LinkButton)
                btnDelete.Attributes.Add("onclick", "javascript:return confirm('确定删除吗?删除以后将无法恢复!');")
    这个没有问题,郁闷!