using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
SqlConnection mycn;
SqlDataAdapter myda;
DataSet ds = new DataSet();
DataSet dsSelDate;
String strConn;
protected void Page_Load(object sender, EventArgs e)
{
// Put user code to initialize the page here
strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
myda = new SqlDataAdapter("Select * FROM EventsTable", strConn);
myda.Fill(ds, "Table");
}
protected void CalendarDRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
// If the month is CurrentMonth
if (!e.Day.IsOtherMonth)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
if ((dr["EventDate"].ToString() != DBNull.Value.ToString()))
{
DateTime dtEvent = (DateTime)dr["EventDate"];
if (dtEvent.Equals(e.Day.Date))
{
e.Cell.BackColor = Color.PaleVioletRed;
}
}
}
}
//If the month is not CurrentMonth then hide the Dates
else
{
e.Cell.Text = "";
}
}
protected void Calendar1_SelectionChanged1(object sender, EventArgs e)
{
//objDatadapter = db.getSqlDataAdapter(data);
//dataset = new DataSet();
//objDatadapter.Fill(dataset, "data");
//GridView_data.DataSource = dataset.Tables["data"];
//GridView_data.DataBind();
myda = new SqlDataAdapter("Select * from EventsTable where EventDate='"+ Calendar1.SelectedDate.ToLongDateString() +"'", strConn);
dsSelDate = new DataSet();
myda.Fill(dsSelDate, "myda");
if (dsSelDate.Tables[0].Rows.Count == 0)
{
DataGrid1.Visible = false;
}
else
{
DataGrid1.Visible = true;
DataGrid1.DataSource = dsSelDate;
DataGrid1.DataBind();
}
}
}
ประมาณนี้
myda = new SqlDataAdapter("Select * from EventsTable where EventDate=@EventDate", strConn);
myda.Command.Parameters.Add("@EventDate", Calendar1.SelectedDate.value);