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
HTML
<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">

VB
//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

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

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.

SQL
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

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

Amit Pathak
http://amitpathak.net/web[^]
 
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