DataGrid列显示如下: DataGrid的列是运行时自动创建的. 订单编号 款式 总数量 Size1 Size2 Size 3
1,我是想在DataGrid动态绑定后,动态添加textbox模板列到 Size1,Size2,Size3
2,DataGrid的所有行都显示出textbox,达到同时多行编辑,而不是一次编辑时才把textbox显示出来
1,我是想在DataGrid动态绑定后,动态添加textbox模板列到 Size1,Size2,Size3
2,DataGrid的所有行都显示出textbox,达到同时多行编辑,而不是一次编辑时才把textbox显示出来
解决方案 »
- javascript 跳到另一页面
- 父路径能打开,完整路径打不开
- 索引问题 在线等
- asp.net使用jQuery的post方法调用一般处理程序是没有执行到handler。是什么原因??
- 刚从ASP转到.NET开发,界面层表示方法头晕啊。请教一个repeater的使用方法
- 一个很老的问题,图片长传,在线等!!
- 怎么循环查找一个dataview里的值?我不会,什么datatable啊我都不会用,
- vs2005无法在web服务器上启动调试,问了好多人,都没法解决,帮帮忙啊!!
- 我的菜单总是被Toolbar中的ToolbarDropDownList挡住,怎么解决
- 求救:web user control的问题
- 怎么没有人回答啊
- 网页总出现错误
DataGrid的所有行都显示出textbox好像默认的就是可以的。
我现在用AutoGernalColumns = false然后用lovecherry的http://www.cnblogs.com/lovecherry/archive/2005/03/26/126102.html方法实现了我的问题.现在有个问题就是,更新时没有办法一次多行更新,因为DataGrid是动态添加的,不能用((TextBox)e.Item.FindControl("idname")).Text来循环取数据.我如果要一次更新多行,该怎么办??
{
TableCell tc = new TableCell();
e.Item.Cells.Add(tc); TextBox tb = new TextBox();
tb.ID = "idname";
tc.Controls.Add(tb);
}
我把DataGrid的AutoGernalColumns = true,然后用你的方法,只会在最后一列生产模板列.还有数据要怎么绑定到textbox???
TableCell tc = new TableCell();
e.Item.Cells.Add(tc);try
TableCell tc = new TableCell();
e.Item.Cells.AddAt(n,tc); //change n
>>>还有数据要怎么绑定到textbox???
add an ItemDataBound event handler for your datagrid, then
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
TextBox tb = e.Item.FindControl("idname") as TextBox;
tb.Text = DataBinder.Eval(e.Item.DataItem,"SomeColumName").ToString();}
BandGrid()
End Sub Private Sub BandGrid()
Dim myDataSet As New DataSet
Dim Sql As String = "select * from orderSize"
Dim i As Int16
Dim FieldName As String
myDataSet = DBAccess.SqlHelper.ExecuteDataset(getConnectionString, CommandType.Text, Sql)
DataGrid1.DataSource = myDataSet.Tables(0)
DataGrid1.DataBind()
End Sub下面是ItemCreated的代码If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim i As Byte
For i = 0 To e.Item.Cells.Count - 1
Dim tc As New TableCell
e.Item.Cells.AddAt(i, tc)
Dim tb As New TextBox
tb.ID = i
tc.Controls.Add(tb)
Next
End If运行后DataGrid的列会多出一倍,是不是要设置AutoGernalColumns =false,
请思归继续关注,谢谢!
For i = 0 To e.Item.Cells.Count - 1
Dim tc As New TableCell
e.Item.Cells.AddAt(i, tc)
???不明白你要干什么, 如果你的目的是要把Size1 Size2 Size 3中的数据放在TextBox里,那么你应该设置这样的Template<asp:TemplateColumn HeaderText="Size1">
<ItemTemplate>
<asp:TextBox id="txtSize1" Text='<%# DataBinder.Eval(Container.DataItem, "Size1") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateColumn><asp:TemplateColumn HeaderText="Size2">
<ItemTemplate>
<asp:TextBox id="txtSize2" Text='<%# DataBinder.Eval(Container.DataItem, "Size2") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Size3">
<ItemTemplate>
<asp:TextBox id="txtSize3" Text='<%# DataBinder.Eval(Container.DataItem, "Size3") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
然后在按钮事件里,这么做for each dgi as DataGridItem in YourDataGrid.Items
dim txt1 as TextBox = DirectCast(dgi.FindControl("txtSize1"), TextBox)
dim txt2 as TextBox = DirectCast(dgi.FindControl("txtSize2"), TextBox)
dim txt3 as TextBox = DirectCast(dgi.FindControl("txtSize3"), TextBox)
'....next还有,你应该这么做初始绑定Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If not Page.IsPostBack then
BandGrid()
end if
End Sub
可能会出现只有Size1 , 也可能会出现 Size1,Size2,Size3,Size4,Size5.
我是想在各Size列加入Textbox.
也就是我之前所说的,在绑定数据源到DataGrid后,再在DataGrid的列里加TextBox
Dim tb As New TextBox
e.Item(i).cell(Size1在第几列).controls.add(tb)
next
每一个cell里面都有很多控件,如果你不想要其他的空间,你可以在add前clear:e.Item(i).cell(Size1在第几列).controls.clear大概是这么写的,具体情况你自己查一下帮助,调试一下。