DataBinding:'System.Data.DataRowView'不包含名为'total_likes'的属性。 [英] DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'total_likes'.

查看:128
本文介绍了DataBinding:'System.Data.DataRowView'不包含名为'total_likes'的属性。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用转发器来显示一些产品列表。现在我必须再向我的转发器添加一个数据字段。我将一个图像添加到转发器中,此图像将显示我的数据字段值是否大于1,如果值为零则不会显示。

I am using repeater to show some product list. Now i have to add one more data field to my repeater. I add one image to repeater and this image will show if my data field value is greater than one and if the value is zero it will not show.

<asp:Image ID="Image1" runat="server" ImageUrl="Images/trustedbusiness.PNG" Visible ='<%# Convert.ToInt16(Eval("total_likes")) >= 1 ? true : false %>' />



Sql查询以绑定转发器:


Sql query to bind repeater:

select r.*, s.s_name, c.category_name, sc.subcategory_name, CASE iam WHEN 1 THEN 'Professional/Business' ELSE 'Individual' End as iamdetail, substring(description,1,250) AS shortdescription, substring(title,1,30) AS shorttitle, substring(address,1,80) AS shortaddress from tbl_adregister r INNER JOIN tbl_state s ON r.state = s.s_id join tbl_category as c on r.category=c.category_id INNER JOIN tbl_adsubcategory sc on r.ad_id=sc.ad_id where country=@country and category=@category

select count(al.email) as total_likes from tbl_adregister r inner join tbl_adlike al on r.ad_id=al.ad_id where al.ad_id=r.ad_id



以前我只使用第一个sql语句,它工作正常,但我必须再添加一个字段,所以我再添加一个sql语句。

现在我收到此错误:DataBinding:'System.Data .DataRowView'不包含名为'total_likes'的属性。

当我分别运行第二个查询时,我得到了正确的结果,即数值。


Previously i am using only first sql statement and it works fine but as i have to add one more field so i add one more sql statement.
Now i got this error : DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'total_likes'.
When i run second query separate then i got correct result i.e numeric value.

推荐答案

第二个查询的结果在另一个结果集中。我怀疑你是否在数据访问层中阅读了它。您需要在第一个查询中返回信息,如下所示:
Results of the second query is in another resultset. I doubt you read it in you data access layer. You need to return the information within the first query like this:
select r.*, s.s_name, c.category_name, sc.subcategory_name, 
	CASE iam WHEN 1 THEN 'Professional/Business' ELSE 'Individual' End as iamdetail,
	substring(description,1,250) AS shortdescription, 
	substring(title,1,30) AS shorttitle, 
	substring(address,1,80) AS shortaddress,
	(select count(al.email) from tbl_adlike al where r.ad_id=al.ad_id) as total_likes
from tbl_adregister r 
	INNER JOIN tbl_state s ON r.state = s.s_id 
	join tbl_category as c on r.category=c.category_id 
	INNER JOIN tbl_adsubcategory sc on r.ad_id=sc.ad_id 
where country=@country and category=@category






这样做:

Hi,

Do it this way:
select 
 count(al.email) as total_likes
 , r.*
 , s.s_name
 , c.category_name
 , sc.subcategory_name
 ,CASE iam WHEN 1 THEN 'Professional/Business' ELSE 'Individual' End as iamdetail
 ,substring(description,1,250) AS shortdescription
 ,substring(title,1,30) AS shorttitle, substring(address,1,80) AS shortaddress 
 FROM tbl_adregister r 
 inner join tbl_adlike al on r.ad_id=al.ad_id
 INNER JOIN tbl_state s ON r.state = s.s_id join tbl_category as c on r.category=c.category_id 
 INNER JOIN tbl_adsubcategory sc on r.ad_id=sc.ad_id 
 where country=@country and category=@category and al.ad_id=r.ad_id





这可能不起作用,我在这里要说的是..仅在上一个查询中添加新列。 />


现在,您正在编写两个数据表,显然您只能绑定到。因此,您正在编写的字段无法绑定,并且您收到此错误



This may not work, what I am trying to say here is.. add your new column in the previous query only.

Now, you are writing two datatables and obviously you can bind to only on. Hence, the field you are writing is not available to bind, and you get this error


我在tbl_adregister中创建了新列(喜欢)...每当用户像任何产品一样增加时一个,所以不用计算其他表中的喜欢,我只使用一个表。
I created new column(likes) in tbl_adregister...whenever user like any product it goes increment by one, so instead of counting likes from other table i simple use only one table.


这篇关于DataBinding:'System.Data.DataRowView'不包含名为'total_likes'的属性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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