可行的,我得到的错误是:为什么我不能在绑定一个的.aspx财产,而它在的.xaml
“strTitle”(PROPERT的名称)这个名字并不在当前存在背景
要非常清楚我会告诉代码:
的Silverlight:
var myData =from xAudioinfo in xResponse.Descendants(ns + "DIDL-Lite").Elements(ns + "item")
select new RMSMedia
{
strTitle =((string)xFolderInfo.Element(dc + "title")).Trim(),
objectID = (int)xFolderInfo.Attribute("id")
};
现在我能在我的XAML绑定此象下面这样:
<TextBlock Text ="{Binding strTitle}" />
但是,这不是在ASP.NET工作。
ASP.NET
var myData =from xAudioinfo in xResponse.Descendants(ns + "DIDL-Lite").Elements(ns + "item")
select new RMSMedia
{
strTitle =((string)xFolderInfo.Element(dc + "title")).Trim(),
objectID = (int)xFolderInfo.Attribute("id")
};
设法使用HTML控制结合:
<asp:Label ID="lbWindCondition" runat="server" Text=<%#strTitle %>></asp:Label>
编辑: @Prisoner ZERO
我的代码结构如下:
public class currentWeatherCondition
{
public string condition { get; set; }
public string temp { get; set; }
public string imageURL { get; set; }
public string humidity { get; set; }
public string windCondition { get; set; }
}
public partial class _Default : System.Web.UI.Page
{
protected void btnGetDetails_Click(object sender, EventArgs e)
{
try
{
var weatherXML = XDocument.Load(weatherURL);
var weatherResult = from weatherDetail in weatherXML.Descendants("current_conditions")
select new currentWeatherCondition
{
condition = ((string)weatherDetail.Element("condition").Attribute("data")).Trim(),
temp = ((string)weatherDetail.Element("temp_c").Attribute("data")).Trim(),
imageURL = ((string)weatherDetail.Element("icon").Attribute("data")).Trim(),
humidity = ((string)weatherDetail.Element("humidity").Attribute("data")).Trim(),
windCondition = ((string)weatherDetail.Element("wind_condition").Attribute("data")).Trim(),
};
}
catch(..)
{
......
}
}
所以我们的意思是我会直接创建_Default
类中的prpoerty或在默认类中创建currentWeatherCondition
对象,然后将其绑定/呈现给控件。
你试过文本= '<%#的eval( “strTitle”)%>' – TheGeekYouNeed
的原因我想它工作在WPF但不是ASP。 net是asp.net没有wpf所具有的绑定上下文概念。推测你将mydata对象绑定到包含文本块的对象。在asp.net中,你必须明确地绑定每个属性。 –