Click here to Skip to main content
15,941,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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">
                    <div runat="server" id="itemPlaceholder" />
                    <% If Eval("ds_SingleDouble") = "S" Then%>
                    <% Else%>                        <td><%#Eval("cd_Player11")%>/<%#Eval("cd_Player12")%></td>
                        <td>&nbsp;vs&nbsp;</td>                        <td><%#Eval("cd_Player21")%>/<%#Eval("cd_Player22")%></td>
                    <% End If%>
<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"
        adoDataSet = New DataSet()
        Dim cmd As SqlCommand = New SqlCommand(cmdSql, connectie)
        champAdapter = New SqlDataAdapter(cmd)
        champAdapter.Fill(adoDataSet, "tbl_Championship")
        ListView1.DataSource = adoDataSet
    End Sub

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,
Updated 20-May-10 1:33am

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.

SELECT  case when ds_SingleDouble='S' then cd_Player11 +' '+ cd_Player21  else cd_Player11 +'/'+ cd_Player12 End as CD_player
 FROM tbl_ChampionshipDetail

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

                           <td>   <% Eval("ds_CD_player") %>

Amit Pathak[^]
Share this answer
Because the # inside <%# Eval("value") %> is what tells the server to do the data binding.
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