asp.net 中如何动态生成DATAGRID的列和数据
我在画面上定义了个DATAGRID1控件代码如下
<TD> <asp:datagrid id= "grdBrand1 " runat= "server " Width= "1176px " CssClass= "Grid " OnItemCreated= "S_fncCustomDataGrid " AllowPaging= "True " AutoGenerateColumns= "False " GridLines= "None " CellPadding= "0 "> </asp:datagrid> </td>
DATAGRID的列增加和数据绑定如下
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn( "UserName ", GetType(Int32)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
Dim column As System.Web.UI.WebControls.BoundColumn
column = New System.Web.UI.WebControls.BoundColumn
column.DataField = "UserName "
column.ItemStyle.Width = New System.Web.UI.WebControls.Unit(333)
column.HeaderText = "xxx "
grdBrand1.Columns.Add(column)
grdBrand1.DataSource = dv
但结果跑出来DATADRID里却没有数据,请问是什么问题
或者我什么地方写错了.哪位朋友知道的话帮帮忙,告诉一下,谢了!
------解决方案--------------------谢谢楼上两位朋友,我刚才把OnItemCreated= "S_fncCustomDataGrid "删掉了
把grdBrand1.DataBind();加了上去,数据是有了,但数据行的最后却有个 " <> ",不知道怎么回事!
还有个问题,如果我要动态增加个BUTTON什么的,该如何实现呀!
----------------------------
" <> "这