动态列回发后自败

编程入门 行业动态 更新时间:2024-10-27 18:32:36
本文介绍了动态列回发后自败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 GridView控件一些绑定列和两个模板列。在这两个模板列,我动态地创建用户控件 A 的DropDownList 和文本框,用户可以修改。

I have a GridView with some BoundFields and two TemplateFields. In these two TemplateFields, I dynamically create UserControls containing a DropDownList and a TextBox, which users can modify.

当我尝试后回传中的值绑定列还在那里得到控件的值但我的动态控件消失。我可以重新创建它们,但它不会让用户的价值...我怎么能他们丢失之前获得这些价值?

When I try to get the values of the controls after a PostBack, the values in BoundFields are still there but my dynamic controls disappears. I can create them again but it won't get the user's values... How can I get these values before they're lost?

下面是我的一些code的:

Here's some of my code :

在的RowDataBound 事件:

In the RowDataBound event:

Select Case type Case "BooleanBis" e.Row.Cells(2).Controls.Clear() Dim list1 As BooleanBisList = New BooleanBisList(avant, False) e.Row.Cells(2).Controls.Add(list1) e.Row.Cells(4).Controls.Clear() Dim list2 As BooleanBisList = New BooleanBisList(apres, True) e.Row.Cells(4).Controls.Add(list2) Case "Boolean" e.Row.Cells(2).Controls.Clear() Dim list3 As BooleanList = New BooleanList(avant, False) e.Row.Cells(2).Controls.Add(list3) e.Row.Cells(4).Controls.Clear() Dim list4 As BooleanList = New BooleanList(apres, True) e.Row.Cells(4).Controls.Add(list4) End Select

在我的按钮单击事件,我试图让用户控制:

In my button click event, I try to get the user control :

Case "String" temp.ChampValeurApres = DirectCast(Tableau1.Rows(i).Cells(selectedColumn).Controls(1), TextBox).Text

但我得到它不存在错误。有人可以给我一个提示吗?

but i get the error that it doesn't exist. Can someone give me a hint please?

推荐答案

您应该创建RowCreated而不是RowDataBound因为本次活动得到每个回发解雇,而的RowDataBound 只会当 GridView控件被数据绑定到它的火力数据源。

You should create dynamic controls in RowCreated instead of RowDataBound because this event gets fired on every postback whereas RowDataBound only will fire when the GridView gets databound to it's DataSource.

动态创建的控件必须用相同的ID每个回发作为之前重新创建,那么他们保留其值在的的ViewState 以及事件将正确触发(FE一个DropDownList的的SelectedIndexChanged 事件)。

Dynamically created controls must be recreated on every postback with the same ID as before, then they retain their values in the ViewState and events will fire correctly(f.e. a DropDownList's SelectedIndexChanged event).

所以,你应该在 RowCreated 创建,并在的RowDataBound 补他们(FE的的DropDownList 数据源/项或文本框 - 文本)。

So you should create them in RowCreated and "fill" them in RowDataBound(f.e. the DropDownList datasource/Items or a TextBox-Text).

更多推荐

动态列回发后自败

本文发布于:2023-10-12 20:44:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485848.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动态   列回发后

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!