内联数据绑定asp.net标签不执行 [英] Inline Data-Binding asp.net tags not executing

查看:116
本文介绍了内联数据绑定asp.net标签不执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我以前能够做到这一点,

My problem is I used to be able to do this,

<当控件的DataBind函数获取时,div runat =servervisible ='<%#CallAFunctionThatReturnsBoolean()%>'>

< div runat="server" visible='<%#CallAFunctionThatReturnsBoolean() %>' >

和CallAFunctionThatReturnsBoolean()将在Page_Load中调用称为隐含,div的可视性将被正确设置。

and CallAFunctionThatReturnsBoolean() will be called in Page_Load when the control's DataBind function gets called implicitly and the div's visibility will be set correctly.

现在由于某种原因,这不会发生,为了使其工作,我将不得不在我的基础页面或我中调用Page.DataBind()。 DataBind()在该页面的Page_Load子目录中,但我并不真的想这样做,尤其是在基础页面类中,因为如果我有一个页面,让我们说一个DataGrid,我已经调用了DataBind()这个DataGrid会被绑定两次,一次从Page.DateBind开始,一次从显式调用datagrid.DataBind()中获取。

Now for some reason this doesn't happen anymore, and to make it work I would have to either call Page.DataBind() in my base Page class or Me.DataBind() in the Page_Load sub in that page, but I don't really want to do this, especially in the base Page class because then if I have a page with let's say a DataGrid in it that I already call the DataBind() function explicitly, then this DataGrid will get bound twice, once from Page.DateBind and once from the explicit call datagrid.DataBind().

任何想法为什么控件的数据绑定事件不再被隐含了?

Any idea why the control's data binding event is not called implicitly anymore?

谢谢

推荐答案

code><%#发生在数据绑定时,<%= 将始终发生在页面正在构建时,无论如何数据绑定。这听起来像是你正在寻找的东西?

The <%# happens for databinding, the <%= will happen always when the page is being built reglardless of any databinding. It sounds like that is what you are looking for?

另外数据绑定是控制级别,所以如果你'DataBind'是一个网格,它不会数据绑定任何其他控件。即使嵌入的模板化控件也不会自动地被数据绑定,除非你把这个网格调用,否则你可以这样做。

Also databinding is control level so if you 'DataBind' a grid, it will not databind any other controls. Even embedded templated controls will not be automatically databound when the grid is called unless you wire the up to do so.

尝试下面的代码,看看它是否改正了你的问题:

Try doing the following and see if it corrects your problem:

<div runat="server" visible='<%= CallAFunctionThatReturnsBoolean() ? "true" : "false" %>' >

如果要求它在数据绑定事件中发生,我更喜欢实现OnDataBinding服务器端,如下所示:

If you require it to occur in the databinding event, I prefer to implement OnDataBinding server side as follows:

// in your aspx
<div runat="server" OnDataBinding="yourDiv_DataBinding">

// in your .cs
protected void yourDiv_DataBinding(object sender, EventArgs e)
{
    HtmlControl div = (HtmlControl)(sender);
    div.Visible = CallAFunctionThatReturnsBoolean();
}

这篇关于内联数据绑定asp.net标签不执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆