|
-
Jan 2nd, 2003, 08:05 AM
#1
Thread Starter
Fanatic Member
Whats wrong with this ..aaarrrggghhh
Can someone tell me whats wrong with this asp.net code?
<asp:TemplateColumn HeaderText="ack" Visible="True">
<ItemTemplate>
<%# if DataSet1.FieldValue("CALLACK", Container) = true then %>
<img align="middle" src='image1.gif'>
<%else%>
<img align="middle" src='iamge2.gif'>
<%end if%>
</ItemTemplate>
</asp:TemplateColumn>
I keep getting the error message :
"Expression expected"
-
Jan 2nd, 2003, 04:35 PM
#2
Hyperactive Member
The <%# %> tags are for databinding, not inline asp, so whatever is inbetween those tags must resolve to a value.
If ... Then is not an Expression that can resolve to a value hence the error, Expression Expected. There are several ways to get around this, one way is to use IIf. so your code would look like:
Code:
<asp:TemplateColumn HeaderText="ack" Visible="True">
<ItemTemplate>
<%# IIf(DataSet1.FieldValue("CALLACK", Container) = True, _
"<img align='middle' src='image1.gif'>", _
"<img align='middle' src='iamge2.gif'>" ) %>
</ItemTemplate>
</asp:TemplateColumn>
I didn't test out this code so i might have missed a quote here or there but you should be able to get the picture.
Here's a different way I did it, like i said there are many ways to do it, just depends on what works for ya:
VB Code:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script language="vb" runat="server">
Sub Page_Load(ByVal sender As Object , ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
bindGrid()
End If
End Sub
Sub bindGrid()
Dim connString As String = "user id=sa;password=sa;database=Scratch;server=DeathAngel;"
Dim cn As New SqlConnection(connString)
Dim cmdText As String = "Select * From Customer"
Dim cmd As New SqlCommand ( cmdText , cn )
cmd.Connection.Open()
gridCustomer.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
gridCustomer.DataBind()
End Sub
Function DrawCallBackImage(ByVal CallBack As object) As String
Dim IsCallBack As Boolean
Dim ImageFileName As String
IsCallBack = CType(CallBack , Boolean)
If IsCallBack Then
ImageFileName = "Image1.gif"
Else
ImageFileName = "Image2.gif"
End If
Return "<img border=""0"" src=""" & ImageFileName & """/>"
End Function
</script>
<html>
<body>
<form id="DataSetDecision" runat="server">
<asp:DataGrid
ID="gridCustomer"
Runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn
DataField="CustomerId"
HeaderText="Cust ID"/>
<asp:TemplateColumn
HeaderText="CallBack">
<ItemTemplate>
<%# DrawCallBackImage ( Container.DataItem ( "CallBack" ) ) %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|