Kon*_*rad 8 asp.net data-binding
所以对于ASP中的双向(双向)数据绑定,我们这样做......
<asp:textbox id="txtField" runat="server"
text='<%# Bind("SomeField") %>'>
</asp:textbox>
Run Code Online (Sandbox Code Playgroud)
SomeField位于DetailsView的DataSource上,作为文本框的容器.
或者,我可以从代码隐藏(使用文本框的OnDataBinding事件)执行此操作:
protected void SomeField_OnDataBinding(object sender, EventArgs e)
{
((TextBox)sender).Text = Eval("SomeField").ToString();
}
Run Code Online (Sandbox Code Playgroud)
但是,EVAL是只读的......如何从代码隐藏中指定Bind(双向)?
我已经设法为我的“边缘情况”找到解决方法。
我正在使用 LLBLGen 子类型,因此需要根据用户选择的单选按钮过滤器切换详细信息视图的数据源。
我尝试使用 <%# Bind(... 以声明方式"在 ASP 中绑定到子类型字段,但这不起作用。
我必须解决代码隐藏“黑客”问题,其中我使用details_view预渲染方法有条件地在详细信息视图中显示控件。
然后,对于每个字段,我有条件地将其设置为 OnDataBinding 中的单向(只读)绑定...
e.g. ((TextBox)sender).Text = Eval("FilePrefix").ToString();
Run Code Online (Sandbox Code Playgroud)
最后,为了将数据推送到数据源中,我破解了DetailsView OnItemInserting/Updating 事件(也有条件)...
e.Values["FilePrefix"] = txtFilePrefix.Text;
Run Code Online (Sandbox Code Playgroud)
这次黑客攻击后我感觉很脏,我想我需要洗个澡......
我仍然希望有人可以提供更干净的方法:-)
| 归档时间: |
|
| 查看次数: |
3811 次 |
| 最近记录: |