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 SkipVought 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
0
0
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.
 
No way to bind the control. What you have to do, is to create a table of events with dates, if you don't already have it. Then pull the table into a datatable or dataset. Use the calendar's DayRenderEvent, and loop through the dataset comparing the date, if so, set the bgcolor.

Jim
 
Thank you for the response. I do not see the datatable as an option under the Data category so I can't drag it over.
 
Are you using .NET2.0? You can create it in code, or use the sqldataadapter.
 
Will you provide a link to instuction how this is done?
 
Check out the second option faq855-5662 on how to fill your DataTable.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Yes, that can be done using the method Jim suggested above.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
If you are looking for us to write code for you, we won't. We will be glad to help if you make a reasonable effort and are having problems. Try your best and post code here if you are having problems or have questions.

Jim
 
Okay, here's what I have:

<asp:Calendar ID="cdrBoardMtng" 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>

In my Code behind:

private void calDayRender(Object source, DayRenderEventArgs e)
{
for(int i = 0; i < DataList1.Items.Count; i++)
{
string dateStart = Convert.ToString(Eval("mtgDateStart"));
string dateEnd = Convert.ToString(Eval("mtgDateEnd"));

if (e.Day.Date.Day.ToString() == dateStart)
{
e.Cell.BackColor = Color.Navy;
}
}
}
 
And the error occurs when building the page:

Error 1 'eventCal.calDayRender(object, System.Web.UI.WebControls.DayRenderEventArgs)' is inaccessible due to its protection level U:\eventCal.aspx 30


This line is referring to this:

OnDayRender="calDayRender
 
That seems to do the trick; however, I got error on this line:

string dateStart = Convert.ToString(Eval("mtgDateStart"));

I want to convert it to Short so I tried this:

string dateStart = Convert.ToDateTime(Eval("mtgDateStart")).ToShortDateString;

But it is not taking that either. How do I convert to short so it does not contain the time and then compare it to the calendar?
 
This is the error message on that line:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
 
Remove the Eval as it says it is for databound objects. Try:
string dateStart = Convert.ToDateTime("mtgDateStart").ToShortDateString;

 
I got this error:

Error 1 Cannot convert method group 'ToShortDateString' to non-delegate type 'string'. Did you intend to invoke the method? U:\eventCal.aspx.cs 23 32 U:\
 
I'm using a DataList and that's why I use the Eval but by removing it, I recieved the above error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top