简体   繁体   English

ASP.NET 和 C# 中的双向数据绑定

[英]Bidirectional DataBinding in ASP.NET and C#

I am writing a page which uses declarative data binding to bind Control values in a web form (inside a repeater) to values from a source DataTable.我正在编写一个页面,该页面使用声明性数据绑定将 web 表单(在转发器内)中的控制值绑定到源 DataTable 中的值。 The binding works great, the repeater's templated controls are filled from the datatable.绑定效果很好,转发器的模板化控件是从数据表中填充的。 My understanding however is that using the <# Bind("SourceColumnName") #> sytnax (as opposed to the Eval() syntax) I should be able to get controls which have had their values updated by the user to bind those values back to the source DataTable .然而,我的理解是,使用 <# Bind("SourceColumnName") #> sytnax(与 Eval() 语法相反)我应该能够获取已由用户更新其值的控件以将这些值绑定回源数据表 Is there a set of circumstances under which a <# Bind("SourceColumnName") #>-type statement will update its source data, not visa versa?是否存在 <# Bind("SourceColumnName") #>-type 语句会更新其源数据的一组情况,反之亦然? To clarify: I am passing a DataTable object to the DataSource field of the repeater in the codebehind, I am NOT making use of a DataSource Control (which would be attached via the DataSourceID property).澄清一下:我将 DataTable object 传递给代码隐藏中中继器的 DataSource 字段,我没有使用 DataSource 控件(将通过 DataSourceID 属性附加)。 Thanks in advance.提前致谢。

"In general, the Bind method should only be used in an EditItemTemplate and an InsertItemTemplate. It should not be used (or, in fact, required) in an ItemTemplate, AlternatingItemTemplate, or SelectedItemTemplate" (c) www.15seconds.com/issue/040630.htm “一般来说,Bind 方法只能在 EditItemTemplate 和 InsertItemTemplate 中使用。它不应该在 ItemTemplate、AlternatingItemTemplate 或 SelectedItemTemplate 中使用(或者实际上是必需的)”(c) www.15seconds.com/issue /040630.htm

That means your container have to have edit capabilities in order to enforce its template to update underlying datasource.这意味着您的容器必须具有编辑功能才能强制其模板更新底层数据源。 Afaik DataRepeater is unable to do that, try to go for either GridView, DetailView or FormView instead. Afaik DataRepeater 无法做到这一点,请尝试使用 go 代替 GridView、DetailView 或 FormView。

The repeater doesn't have Bidirectional databinding support.中继器不支持Bidirectional databinding You can only create the item using the DataItem.您只能使用 DataItem 创建项目。

You have to loop the repeater items and extract the values from the control to update.您必须循环中继器项目并从控件中提取值以进行更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM