EVAL的IF声明() [英] IF Statement by EVAL()

查看:96
本文介绍了EVAL的IF声明()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



我是初学者,我想问一个有关EVAL的IF声明的问题(字段)。



这是我的代码.ASPX

Dear all,

I am a beginner and I want to ask a question regarding IF statement for EVAL("field").

Here is my code in .ASPX

<asp:ListView ID="ListView1" runat="server">
            <LayoutTemplate>
                <table>
                    <div runat="server" id="itemPlaceholder" />
                </table>
            </LayoutTemplate>
	        <ItemTemplate>
                <tr>
                    <% If Eval("ds_SingleDouble") = "S" Then%>
                        <td><%#Eval("cd_Player11")%></td>
                        <td>&nbsp;vs&nbsp;</td>
                        <td><%#Eval("cd_Player21")%></td>
                    <% Else%>                        <td><%#Eval("cd_Player11")%>/<%#Eval("cd_Player12")%></td>
                        <td>&nbsp;vs&nbsp;</td>                        <td><%#Eval("cd_Player21")%>/<%#Eval("cd_Player22")%></td>
                    <% End If%>
                   </tr>
            </ItemTemplate></asp:ListView> 
<asp:ListView ID="ListView1" runat="server">




//My code in .ASPX.VB
    Private Sub getData()
        Dim adoDataSet As DataSet
        Dim champAdapter As SqlDataAdapter
        Dim cmdSql As String = "SELECT *, ds_SingleDouble FROM tbl_ChampionshipDetail, tbl_Discipline "
        cmdSql = cmdSql + "WHERE cd_ChampionshipID = " + Request.QueryString("id") + " AND cd_Qualification = 'SF'"
        cmdSql = cmdSql + " AND cd_DisciplineID = ds_ID"
        connectie.Open()
        adoDataSet = New DataSet()
        Dim cmd As SqlCommand = New SqlCommand(cmdSql, connectie)
        champAdapter = New SqlDataAdapter(cmd)
        champAdapter.Fill(adoDataSet, "tbl_Championship")
        connectie.Close()
        ListView1.DataSource = adoDataSet
        ListView1.DataBind()
    End Sub



当我运行代码时,出现错误:

数据绑定方法,如Eval(),XPath()和Bind()只能在数据绑定控件的上下文中使用。



错误是在IF语句发生的行:<%If Eval(ds_SingleDouble)=S然后%> ; in .ASPX代码



有人可以帮帮我吗?

提前致谢,

Juliando


When I run the code, I get an error:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

The error is by the line where the IF statement take place: <% If Eval("ds_SingleDouble") = "S" Then%> in .ASPX code

Can anybody help me please?
Thanks in advance,
Juliando

推荐答案

使用以下查询来解决您的问题,以便在.aspx页面上使用if条件,您可以通过sql查询获得所需的结果。



Use below query to solve your problem so that in place of using "if" condition on .aspx page you can get desired result by sql query.

<pre lang="sql">SELECT  case when ds_SingleDouble='S' then cd_Player11 +' '+ cd_Player21  else cd_Player11 +'/'+ cd_Player12 End as CD_player<br />
 FROM tbl_ChampionshipDetail</pre><br />
<pre></pre>





使用上面的查询你可以在.aspx页面中使用如下所示的方式





by using above query you can use in .aspx page in manner like below shown

<ItemTemplate>
                        <tr>
                           <td>   <% Eval("ds_CD_player") %>
                </td>
                           </tr>
                  </ItemTemplate>



Amit Pathak

http://amitpathak.net/web [ ^ ]


因为#inside<%#Eval(value)%>是告诉服务器进行数据绑定的。
Because the # inside <%# Eval("value") %> is what tells the server to do the data binding.


这篇关于EVAL的IF声明()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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