Hi I have a calendar that shows some events from a db, when i start the page, it shows the calendar fine, but if i then go to a month that i know i have some events in, then i get this error:
DataBindingMethods such asEval
(),XPath() and
Bind() canonly be used inconjunction with adata
boundobject.
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Partial Class calendar
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim startDate As DateTime = New DateTime(cal1.VisibleDate.Year, cal1.VisibleDate.Month, 1).AddDays(-7)
Dim endDate As DateTime = New DateTime(cal1.VisibleDate.Date.AddMonths(1).Year, cal1.VisibleDate.Date.AddMonths(1).Month, 1).AddDays(7)
cal1.DataSource = GetEventData(startDate, endDate)
End If
End Sub
Function GetEventData(ByVal startDate As DateTime, ByVal endDate As DateTime) As DataTable
Using connection As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString)
Using cmd As OleDbCommand = New OleDbCommand()
cmd.Connection = connection
cmd.CommandText = String.Format("SELECT * FROM eventlist " & _
"WHERE listdate >= #{0}#" & _
"AND listdate <= #{1}#", _
startDate, endDate)
Using adapter As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim ds As New DataSet()
adapter.Fill(ds)
connection.Close()
Return ds.Tables(0)
End Using
End Using
End Using
End Function
Sub MonthChange(ByVal o As Object, ByVal e As MonthChangedEventArgs)
Dim startDate As DateTime = e.NewDate.AddDays(-7)
Dim endDate As DateTime = e.NewDate.AddMonths(1).AddDays(7)
cal1.DataSource = GetEventData(startDate, endDate)
End Sub
End Class
I have made relationship between listcategory and catid, if listcategory = 2 then i need to use the catid = 2 from event_cat. aswell as the catimage and catcolor from this (catid = 2) record, how do i do that !?
Test ur sql query., I think u missed the catimage column to select.
In ur select query, u have select only the column available in the event-list table. but the catimage column is in another table. so u didnot retrieve the catimage column value from that query,so u got that error.
siraero
Member
419 Points
604 Posts
Eval() error in calendar
Jun 08, 2012 10:56 PM|LINK
Hi I have a calendar that shows some events from a db, when i start the page, it shows the calendar fine, but if i then go to a month that i know i have some events in, then i get this error:
Data Binding Methods such as Eval (), XPath () and Bind () can only be used in conjunction with a data bound object.
For the line
<a href='eventDetail.aspx?id=<%# Eval("listid")%>'>My code is
<% @Register Namespace="DataControls" Assembly="DataCalendar" TagPrefix="dc" %> <%@ Page Language="VB" AutoEventWireup="false" CodeFile="calendar.aspx.vb" Inherits="calendar" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> a {text-decoration: none;} a:hover {text-decoration: underline;} </style> </head> <body> <form id="form1" runat="server"> <div> <h3>Events from an Access database through OleDb</h3> <dc:DataCalendar id="cal1" runat="server" width="100%" DayField="listdate" VisibleDate="1/7/2012" OnVisibleMonthChanged="MonthChange"> <DayStyle HorizontalAlign="Left" VerticalAlign="Top" Font-Size="8" Font-Name="Arial" BackColor="lightYellow" /> <OtherMonthDayStyle BackColor="LightGray" ForeColor="DarkGray" /> <ItemTemplate> <br /> <a href='eventDetail.aspx?id=<%# Eval("listid")%>'> <img src='images/<%# Eval("catimage")%>' height="12" width="12" align="absmiddle" border="0" /> <font color='<%# Eval("catcolor")%>'> <%# Eval("listtitle")%> </font> </a> </ItemTemplate> <NoEventsTemplate> <br /> <br /> <br /> <br /> <br /> </NoEventsTemplate> </dc:DataCalendar> </div> </form> </body> </html>CB
Imports System.IO Imports System.Data Imports System.Data.OleDb Partial Class calendar Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then Dim startDate As DateTime = New DateTime(cal1.VisibleDate.Year, cal1.VisibleDate.Month, 1).AddDays(-7) Dim endDate As DateTime = New DateTime(cal1.VisibleDate.Date.AddMonths(1).Year, cal1.VisibleDate.Date.AddMonths(1).Month, 1).AddDays(7) cal1.DataSource = GetEventData(startDate, endDate) End If End Sub Function GetEventData(ByVal startDate As DateTime, ByVal endDate As DateTime) As DataTable Using connection As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString) Using cmd As OleDbCommand = New OleDbCommand() cmd.Connection = connection cmd.CommandText = String.Format("SELECT * FROM eventlist " & _ "WHERE listdate >= #{0}#" & _ "AND listdate <= #{1}#", _ startDate, endDate) Using adapter As OleDbDataAdapter = New OleDbDataAdapter(cmd) Dim ds As New DataSet() adapter.Fill(ds) connection.Close() Return ds.Tables(0) End Using End Using End Using End Function Sub MonthChange(ByVal o As Object, ByVal e As MonthChangedEventArgs) Dim startDate As DateTime = e.NewDate.AddDays(-7) Dim endDate As DateTime = e.NewDate.AddMonths(1).AddDays(7) cal1.DataSource = GetEventData(startDate, endDate) End Sub End ClassssjGanesh
Participant
1928 Points
1352 Posts
Re: Eval() error in calendar
Jun 09, 2012 03:39 AM|LINK
Mark as answer,if it helped U!
siraero
Member
419 Points
604 Posts
Re: Eval() error in calendar
Jun 09, 2012 08:58 AM|LINK
Hi i tryed with Databinder.Eval() it dident work then i tryed Container.DataItem that worked, but now i get another error here, with the line 2
Error: the column 'catimage' it not at part of the table.
<a href='eventDetail.aspx?id=<%# Container.DataItem("listid")%>'> <img src='images/<%# Container.DataItem("catimage")%>' height="12" width="12" align="absmiddle" border="0" /> <font color='<%# Container.DataItem("catcolor")%>'>I thing its bc my SQL line is bad:
cmd.CommandText = String.Format("SELECT * FROM event_list " & _ "WHERE listdate >= #{0}#" & _ "AND listdate <= #{1}#", _ startDate, endDate)I have 3 table.
DatabaseDB.mdb
event_list
- listid (key/Auto)
- listdate
- listcategory
- listtitle
event_cat
- catid (key/Auto)
- cattitle
I have made a relationship between listcategory and catid.
But have do i select the listdate and then get the cattitle as well from the other table, if i dont do it with my SQL line !??
ssjGanesh
Participant
1928 Points
1352 Posts
Re: Eval() error in calendar
Jun 09, 2012 09:02 AM|LINK
You have made relationship for only two tables and bring only the column from those two tables.
In those table there is no column name "catimage". so that error comes.
Mark as answer,if it helped U!
siraero
Member
419 Points
604 Posts
Re: Eval() error in calendar
Jun 09, 2012 09:30 AM|LINK
forgot to add the catimage to the last table, its in there sry.
So how do i do !?
siraero
Member
419 Points
604 Posts
Re: Eval() error in calendar
Jun 09, 2012 09:38 AM|LINK
sry again..
Yes there is 3 table but its only the 2 i need help with now.
The table is:
DatabaseDB.mdb
event_list
- listid (key/Auto)
- listdate
- listcategory
- listtitle
event_cat
- catid (key/Auto)
- cattitle
- catimage
- catcolor
I have made relationship between listcategory and catid, if listcategory = 2 then i need to use the catid = 2 from event_cat. aswell as the catimage and catcolor from this (catid = 2) record, how do i do that !?
ssjGanesh
Participant
1928 Points
1352 Posts
Re: Eval() error in calendar
Jun 09, 2012 09:41 AM|LINK
Test ur sql query., I think u missed the catimage column to select.
In ur select query, u have select only the column available in the event-list table. but the catimage column is in another table. so u didnot retrieve the catimage column value from that query,so u got that error.
Mark as answer,if it helped U!
siraero
Member
419 Points
604 Posts
Re: Eval() error in calendar
Jun 09, 2012 12:41 PM|LINK
Hi again im new to this and not a pro. but have tryed this, but it dont work...
cmd.CommandText = String.Format("SELECT event_list.listtitle, event_list.listdescription, event_list.listdate, event_cat.cattitle, event_cat.catimage, event_cat.catcolor " & _ "FROM event_list " & _ "LEFT JOIN event_cat " & _ "ON event_list.listcategory=event_cat.catid " & _ "WHERE event_list.listdate >= #{0}#" & _ "AND event_list.listdate <= #{1}#", _ startDate, endDate)ssjGanesh
Participant
1928 Points
1352 Posts
Re: Eval() error in calendar
Jun 09, 2012 12:47 PM|LINK
Sorry dear.,
Instead of using that query , whats the problem to use stored procedure.....
Mark as answer,if it helped U!
siraero
Member
419 Points
604 Posts
Re: Eval() error in calendar
Jun 09, 2012 12:57 PM|LINK
Im new to this, "stored procedure".... what do u mean !?