2013-02-12 57 views
1

我有內GridView的一個標籤,我想查詢像這樣的東西綁定吧..自定義綁定代碼表達式中的SQL查詢?

select COUNT(*) 
from tbl_like 
inner join Scrap on tbl_like.scrapid=Scrap.Id 
where tbl_like.likestatus=1 and tbl_like.scrapid='DataBinder.Eval(Container.DataItem,"ScrapId")' 

我知道上面的代碼將無法正常工作,我能做些什麼,使工作?

源代碼:

<ItemTemplate> 
    <asp:Label ID="Label1" runat="server" Text='<%# "Id of Scrap:"+DataBinder.Eval(Container.DataItem,"ScrapId") %>'></asp:Label> 
</ItemTemplate> 

回答

0

這裏是如何得到這個工作:

  1. 建立在後面的代碼保護的靜態方法將返回所需的值,並Accpet頭您提供
  2. 參數
  3. 更新您的項目模板看起來像這樣

    <ItemTemplate> 
         <asp:Label ID="Label1" runat="server" Text='<%# WebPageName.StaticMethodName((int)Eval("ScrapId")) %>' /> 
    </ItemTemplate> 
    
+0

它工作得很好。謝謝! – Arbaaz 2013-02-13 13:43:03