Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to bind Calendar to SqlDataSource?

Status
Not open for further replies.

onechuck

IS-IT--Management
Feb 14, 2006
79
US
Is there a way to bind a Calendar to a SqlDataSource? I like to create a calendar where if there is an event scheduled it will show up as highlighted on the calendar. Help is much appreciated.
 
Ok how about trying:

string dateStart = Convert.ToDateTime("mtgDateStart");
dateStart = dateStart.ToShortDateString;
 
Okay, this time I got on this line:

if (e.Day.Date.Day.ToString() == dateStart)

The error is:

Error 2 Operator '==' cannot be applied to operands of type 'string' and 'System.DateTime' U:\eventCal.aspx.cs 31 17 U:\

 
First error:
Error 1 Cannot convert method group 'ToShortDateString' to non-delegate type 'System.DateTime'. Did you intend to invoke the method? U:\eventCal.aspx.cs 25 25 U:\

On this line:
dateStart = dateStart.ToShortDateString;

Second error:
Error 2 Operator '==' cannot be applied to operands of type 'string' and 'method group' U:\eventCal.aspx.cs 31 17 U:\

On this line:
if (e.Day.Date.Day.ToString() == dateStart.ToString)
 
YOu have to make sure your datatypes match. Obviously there is a problem where you have vars defined as date or datetime and some as string. Go through and make them consistant.
 
This is what I have in the SQL server.

CREATE TABLE eventMtg_date (
mtgID int NOT NULL,
mtgTitle varchar(250) NOT NULL default '',
mtgDscrt text,
mtgPlace varchar(100) default NULL,
mtgLocation varchar(100) default NULL,
mtgDateStart datetime NOT NULL default '0000-00-00 00:00:00',
mtgDateEnd datetime NOT NULL default '0000-00-00 00:00:00',
mtgRecurring varchar(64) default NULL,
PRIMARY KEY (mtgID)
);
 
You have to check how your variables in your C# code are defined, and do conversions as necessary.
 
Well, I don't have any variable define anywhere else other than what is showing in my code behind showing above. Here's all I have in my .aspx page.
<form id="cldrBoardMeeting" runat="server">
<asp:DataList ID="DataList1" runat="server" DataSourceID="slqBoardMtng">
<ItemTemplate>
mtgDateEnd:
<asp:Label ID="mtgDateEndLabel" runat="server" Text='<%# Eval("mtgDateEnd") %>'>
</asp:Label><br />
mtgDateStart:
<asp:Label ID="mtgDateStartLabel" runat="server" Text='<%# Eval("mtgDateStart") %>'>
</asp:Label><br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="Black"
BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black"
Height="250px" NextPrevFormat="ShortMonth" Width="330px" OnDayRender="calDayRender">
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<TodayDayStyle BackColor="#999999" ForeColor="White" />
<DayStyle BackColor="#CCCCCC" />
<OtherMonthDayStyle ForeColor="#999999" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" />
<DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" Height="8pt" />
<TitleStyle BackColor="#333399" BorderStyle="Solid" Font-Bold="True" Font-Size="12pt"
ForeColor="White" Height="12pt" />
</asp:Calendar>
</form>
 
Okay, here's what I did so far:

if (e.Day.Date.Day.ToString() == Convert.ToString(Eval("mtgDateStart")))
{
e.Cell.BackColor = Color.Navy;
}

I do not get any error during compilation but I received this error when viewing through IE.

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Source Error:

Line 29: //string dateEnd = Eval("mtgDateEnd");
Line 30:
Line 31: if (e.Day.Date.Day.ToString() == Convert.ToString(Eval("mtgDateStart")))
Line 32: {
Line 33: e.Cell.BackColor = Color.Navy;


Source File: e:\ Line: 31
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top