I have got a problem in creating database event calendar asp sample
Hello,
These are sample on how to create an events Calendar using ASP.NET. Database
works on IE and Firefox.
1.On a Database Design, there is a table and its called "Schedules",
Figured table has following fields:
*a Schedule ID
*Title
*Schedule date
Next is the DataSet. Learn it on the given sample below;
private DataSet GetData()
{
string connectionString = "Server=localhost;Database=School;Trusted_Connection=true";
SqlConnection myConnection = new SqlConnection(connectionString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM Schedules", myConnection);
DataSet ds = new DataSet();
ad.Fill(ds);
return ds;
}
2. Fill the Data from Database
Follow on this next sample
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
DataSet ds = GetData();
string link = "<a href='ScheduleDetails.aspx?scheduleID=";
string s = e.Day.Date.ToShortDateString();
e.Cell.Text = e.Day.Date.Day.ToString() + "<BR>";
LiteralControl l = new LiteralControl();
l.Text = e.Day.Date.Day.ToString() + "<BR>";
e.Cell.Controls.Add(l);
foreach (DataRow row in ds.Tables[0].Rows)
{
string scheduledDate = Convert.ToDateTime(row["ScheduleDate"]).ToShortDateString();
if (scheduledDate.Equals(s))
{
LinkButton lb = new LinkButton();
lb.Text = link + (int)row["ScheduleID"] + "'>" + row["Title"] as String + "</a>" + "<BR>";
e.Cell.Controls.Add(lb);
}
}
HtmlAnchor anchor = new HtmlAnchor();
anchor.InnerHtml = "Add";
string method = "ShowAddTaskPane(event,'" + e.Day.Date.ToShortDateString() + "')";
anchor.href="#";
anchor.Attributes.Add("onclick", method);
e.Cell.Controls.Add(anchor);
}
The ADD button could also help you create quick adding events.
3. Now the Adding New Events;
It is not necessary to use another page to add new events, you can do it on the same page.
*check this sample 1 task is to create "DIV" this contains TEXTBOX and CONTROL button to ADD Event.
<div id="AddTaskPane" onblur="this.style.visibility='hidden'" style="position:absolute; visibility:hidden; width:200px; height:100px; background-color:#FFFF66">
Enter Title: <asp:TextBox ID="txtTitle" runat="server" />
<asp:Button ID="Btn_AddTask" runat="server" Text="Add Task" OnCommand="Btn_AddTask_Command" />
</div>
The <DIV> is made invisible and will only appear when the “Add” link is clicked. The code to create the “Add” link is inside the DayRender event but I am re-pasting it so that you will have a better idea.
HtmlAnchor anchor = new HtmlAnchor();
anchor.InnerHtml = "Add";
string method = "ShowAddTaskPane(event,'" + e.Day.Date.ToShortDateString() + "')";
anchor.href="#";
anchor.Attributes.Add("onclick", method);
e.Cell.Controls.Add(anchor);
The ShowAddTaskPane is fired when the user clicks on the “Add” link. Let’s take a look at the ShowAddTaskPane method.
function ShowAddTaskPane(e,selectedDate)
{
var ev = e || window.event;
document.getElementById("AddTaskPane").style.visibility = 'visible';
document.getElementById("AddTaskPane").style.top = ev.clientY;
document.getElementById("AddTaskPane").style.left = ev.clientX;
CallServer(selectedDate,'');
}
it will show like this on the image:
hope this codes could help you in any ways.
Thomas