Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.NET
<asp:Image ID="Image1" runat="server" ImageUrl="Images/trustedbusiness.PNG" Visible ='<%# Convert.ToInt16(Eval("total_likes")) >= 1 ? true : false %>' />

Sql query to bind repeater:
SQL
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

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.
Posted
Comments
Mathew Soji 20-Nov-14 7:20am    
This means column "total_likes" you have specified with the data bound control is not present in the data returned from database . Please debug for details .
Raj Negi 20-Nov-14 7:40am    
when i run query separate total_likes has value but dont know why it is giving error.

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:
SQL
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
 
Share this answer
 
Comments
Raj Negi 20-Nov-14 8:16am    
great! It works but now another problem occur...now only those products are show which has one or more than one like. Other products are not showing which has no likes. I just want to show and hide the image on products according to total_likes value.
Tomas Takac 20-Nov-14 8:23am    
Really? This query should return the same number of rows as your original. As you can see I didn't add any join or where condition. The change is in the select list only.
Raj Negi 20-Nov-14 8:35am    
yes you are right, i am also surprised. I will look into it and will tell you when it works. Anyway thanks for your answer. :)
Hi,

Do it this way:
SQL
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
 
Share this answer
 
Comments
Tomas Takac 20-Nov-14 7:45am    
Are you sure this is correct? Count without group by?
Raj Negi 20-Nov-14 7:47am    
Column 'tbl_adregister.ad_id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900