2013-02-12 55 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