閲覧総計:&counter(); (本日:&counter(today); 昨日:&counter(yesterday);) カレンダ コントロールのセルに情報を表示する方法を確認した。 10/08/09 #ref(SqlCalCellDisp02.jpg); 参考にしたページは↓こちら。 「Calendarコントロールのセルに任意のデータを埋め込むには?」05/03/18 http://www.atmarkit.co.jp/fdotnet/dotnettips/277aspcalceldata/aspcalceldata.html ところが、DBへの接続手法がASP.NET2.0以降は、記事内容(ASP.NET1.X)から変更にな っているので、「DBへの接続」のコードを↓記事を参考に全面的に改造した。 「データソース・コントロールでいってみよう(前編)」 06/07/29 http://www.atmarkit.co.jp/fdotnet/vs2005db/vs2005db_06/vs2005db_06_03.html また、実際にはDBにMS-Accessを利用したいので、↓このページの情報を参考に、 DBをSQL Server2008→MS-Access2003に変更し、正常に稼働する事を確認した。 「ASP.NET アクセスデータにアクセスする(コーディング)」 http://3939deb.seesaa.net/article/107785168.html また、参考情報としてSqlDataSourceコントロールを利用し実現した場合のコードを掲載 した。コード量が少ない所を比較して欲しい。 10/08/10 ★項目をクリックするとそのページに飛べます↓ #contents 開発環境:VWD2008 + Access2003 + SQL Server2008 サーバ:ASP.NET3.5 + Access2003 【機能】DBの予定情報をカレンダに表示する。 *DBにSQL Server2008を使用した場合 [#u32cb928] 【稼働画面】 #ref(SqlScheduleDesign01.JPG); #ref(SqlScheduleData01.JPG); #ref(SqlCalCellDisp01.JPG); 【web.configのデータ接続文字列の設定】 SqlServerDBへの接続名として"MySqlServerDB”がweb.configの最初の方の<appSettings> と<system.web>の間に<connectionStrings>として以下の通り記述されている事を前提とする。 <connectionStrings> <add name="MySqlServerDB" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SQLCalendar.mdf;Integrated Security=True;Use r Instance=True" providerName="System.Data.SqlClient" /> </connectionStrings> 【sqlCalCellDisp.aspx】 <%@ Page Language="VB" ContentType="text/html" %> <%@ Import Namespace="System.Data.Common" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="Server"> ' それぞれの日付セルをレンダリングするタイミングで実行 Sub cal_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Dim setting As ConnectionStringSettings = _ ConfigurationManager.ConnectionStrings("MySqlServerDB") Dim factory As DbProviderFactory = _ DbProviderFactories.GetFactory(setting.ProviderName) Using objDb As DbConnection = factory.CreateConnection() objDb.ConnectionString = setting.ConnectionString ' 出力する日付セルに対応するスケジュール情報を抽出 Dim objCom As DbCommand = factory.CreateCommand() objCom.CommandText = "SELECT [ID],[title],[sdate],[stime],[etime] FROM [schedule01] WHERE [sdate]=@sdate ORDER BY [stime] ASC" objCom.Connection = objDb Dim objPrm As DbParameter = factory.CreateParameter() objPrm.ParameterName = "@sdate" objPrm.Value = e.Day.Date.ToString("yyyy/MM/dd") objCom.Parameters.Add(objPrm) objDb.Open() Dim objRd As DbDataReader = objCom.ExecuteReader() ' 取得したスケジュール情報を基に ' LiteralControl(固定文字列)を生成し、 ' 日付セル(e.Call)配下のコントロールとして追加 Do While objRd.Read() e.Cell.Controls.Add(New LiteralControl("<br />" & String.Format("{0}〜{1}:{2}", objRd.GetString(3), objRd.GetString(4), objRd.G etString(1)))) Loop End Using End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>スケジュールをカレンダー上に表示する</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Calendar id="cal" runat="server" DayHeaderStyle-BackColor="#FFCC66" onDayRender="cal_DayRender" ShowGridLines="true" BorderWidth="3" BorderColor="Black" Font-Name="Verdana" Font-Size="10px" TitleStyle-BackColor="#FFCC66" TitleStyle-Font-Size="12px" TitleStyle-Font-Bold="true" DayStyle-VerticalAlign="Top" DayStyle-Height="50px" DayStyle-Width="14%" SelectedDayStyle-BackColor="Navy" ShowNextPrev="True" NextPrevFormat="FullMonth"> <SelectedDayStyle BackColor="#CC5533" /> </asp:Calendar> <br /> </div> </form> </body> </html> 【参考にしたページ】 1.「Calendarコントロールのセルに任意のデータを埋め込むには?」05/03/18 http://www.atmarkit.co.jp/fdotnet/dotnettips/277aspcalceldata/aspcalceldata.html 2.「データソース・コントロールでいってみよう(前編)」 06/07/29 http://www.atmarkit.co.jp/fdotnet/vs2005db/vs2005db_06/vs2005db_06_03.html - 1 -- [[1]] &new{2012-03-12 (月) 20:58:28}; - 1 -- [[1]] &new{2012-03-12 (月) 20:58:31}; - 1 -- [[-1']] &new{2012-03-12 (月) 20:58:32}; -- 1' -- [[1]] &new{2012-03-12 (月) 20:58:33}; - 1 -- [[1]] &new{2012-03-12 (月) 20:58:34}; - 1 -- [[1]] &new{2012-04-29 (日) 02:13:59}; - 1 -- [[1]] &new{2012-04-29 (日) 02:14:03}; - 1 -- [[-1']] &new{2012-04-29 (日) 02:14:04}; -- 1' -- [[1]] &new{2012-04-29 (日) 02:14:05}; - 1 -- [[1]] &new{2012-04-29 (日) 02:14:06}; - 1 -- [[1]] &new{2012-06-29 (金) 17:06:38}; - 1 -- [[1]] &new{2012-06-29 (金) 17:06:42}; - 1 -- [[-1']] &new{2012-06-29 (金) 17:06:43}; -- 1' -- [[1]] &new{2012-06-29 (金) 17:06:44}; - 1 -- [[1]] &new{2012-06-29 (金) 17:06:45}; - 1 -- [[1]] &new{2012-07-13 (金) 18:12:51}; - 1 -- [[1]] &new{2012-07-13 (金) 18:12:54}; - 1 -- [[-1']] &new{2012-07-13 (金) 18:12:55}; -- 1' -- [[1]] &new{2012-07-13 (金) 18:12:56}; - 1 -- [[1]] &new{2012-07-13 (金) 18:12:57}; - 1 -- [[1]] &new{2012-08-26 (日) 21:06:02}; - 1 -- [[1]] &new{2012-08-26 (日) 21:06:05}; - 1 -- [[-1']] &new{2012-08-26 (日) 21:06:07}; -- 1' -- [[1]] &new{2012-08-26 (日) 21:06:08}; - 1 -- [[1]] &new{2012-08-26 (日) 21:06:09}; - 1 -- [[1]] &new{2013-10-21 (月) 11:57:32}; - 1 -- [[1]] &new{2013-10-21 (月) 11:57:41}; - 1 -- [[-1']] &new{2013-10-21 (月) 11:57:46}; -- 1' -- [[1]] &new{2013-10-21 (月) 11:57:48}; - 1 -- [[1]] &new{2013-10-21 (月) 11:57:52}; #comment_nospam - 1 -- [[1]] &new{2013-10-21 (月) 11:57:38}; - 1 -- [[1]] &new{2012-08-26 (日) 21:06:04}; - 1 -- [[1]] &new{2012-07-13 (金) 18:12:53}; - 1 -- [[1]] &new{2012-06-29 (金) 17:06:41}; - 1 -- [[1]] &new{2012-04-29 (日) 02:14:02}; - 1 -- [[1]] &new{2012-03-12 (月) 20:58:30}; #vote(参考になった[0],ふつう[0],参考にならなかった[0]) ~ ~ ~ *DBにMS-Access2003を使用した場合 [#fca0772c] 【ポイント】 プログラムの最初の方に記述されているDB接続名を"MySqlServerDB"から→"MyAccessDB" に変更するだけで使用DBをSQL ServerからMS-Accessに変更できる。 (Factoryパターンを用いて汎用的なコードで記述している為、接続DBを変更するだけで どのDBにも接続できるコード記述になっているのが特徴) Dim setting As ConnectionStringSettings = _ ConfigurationManager.ConnectionStrings("MyAccessDB") 【稼働画面】 #ref(AccessScheduleDesign01.JPG); #ref(AccessSchedule01.JPG); #ref(CalCellDisp01.JPG); 【web.configのデータ接続文字列の設定】 MS-AccessDBへの接続名として"MyAccessDB”がweb.configの最初の方の<appSettings> と<system.web>の間に<connectionStrings>として以下の通り記述されている事を前提とする。 (参考)[[AccessDBの接続文字列の登録法]] <connectionStrings> <add name="MyAccessDb" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\AccessDB.mdb" providerName="System.Data.OleDb" /> </connectionStrings> 【acCalCellDisp.aspx】 <%@ Page Language="VB" ContentType="text/html" %> <%@ Import Namespace="System.Data.Common" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="Server"> ' それぞれの日付セルをレンダリングするタイミングで実行 Sub cal_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Dim setting As ConnectionStringSettings = _ ConfigurationManager.ConnectionStrings("MyAccessDB") Dim factory As DbProviderFactory = _ DbProviderFactories.GetFactory(setting.ProviderName) Using objDb As DbConnection = factory.CreateConnection() objDb.ConnectionString = setting.ConnectionString ' 出力する日付セルに対応するスケジュール情報を抽出 Dim objCom As DbCommand = factory.CreateCommand() objCom.CommandText = "SELECT [ID],[title],[sdate],[stime],[etime] FROM [schedule01] WHERE [sdate]=@sdate ORDER BY [stime] ASC" objCom.Connection = objDb Dim objPrm As DbParameter = factory.CreateParameter() objPrm.ParameterName = "@sdate" objPrm.Value = e.Day.Date.ToString("yyyy/MM/dd") objCom.Parameters.Add(objPrm) objDb.Open() Dim objRd As DbDataReader = objCom.ExecuteReader() ' 取得したスケジュール情報を基に ' LiteralControl(固定文字列)を生成し、 ' 日付セル(e.Call)配下のコントロールとして追加 Do While objRd.Read() e.Cell.Controls.Add(New LiteralControl("<br />" & String.Format("{0}〜{1}:{2}", objRd.GetString(3), objRd.GetString(4), objRd.G etString(1)))) Loop End Using End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>スケジュールをカレンダー上に表示する</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Calendar id="cal" runat="server" DayHeaderStyle-BackColor="#FFCC66" onDayRender="cal_DayRender" ShowGridLines="true" BorderWidth="3" BorderColor="Black" Font-Name="Verdana" Font-Size="10px" TitleStyle-BackColor="#FFCC66" TitleStyle-Font-Size="12px" TitleStyle-Font-Bold="true" DayStyle-VerticalAlign="Top" DayStyle-Height="50px" DayStyle-Width="14%" SelectedDayStyle-BackColor="Navy" ShowNextPrev="True" NextPrevFormat="FullMonth"> <SelectedDayStyle BackColor="#CC5533" /> </asp:Calendar> <br /> </div> </form> </body> </html> 【参考にしたページ】 1.「Calendarコントロールのセルに任意のデータを埋め込むには?」05/03/18 http://www.atmarkit.co.jp/fdotnet/dotnettips/277aspcalceldata/aspcalceldata.html 2.「データソース・コントロールでいってみよう(前編)」 06/07/29 http://www.atmarkit.co.jp/fdotnet/vs2005db/vs2005db_06/vs2005db_06_03.html 3.「ASP.NET アクセスデータにアクセスする(コーディング)」 http://3939deb.seesaa.net/article/107785168.html - 1 -- [[1]] &new{2012-03-12 (月) 20:58:51}; - 1 -- [[1]] &new{2012-03-12 (月) 20:58:54}; - 1 -- [[-1']] &new{2012-03-12 (月) 20:58:55}; -- 1' -- [[1]] &new{2012-03-12 (月) 20:58:56}; - 1 -- [[1]] &new{2012-03-12 (月) 20:58:57}; - 1 -- [[1]] &new{2012-04-29 (日) 02:14:23}; - 1 -- [[1]] &new{2012-04-29 (日) 02:14:26}; - 1 -- [[-1']] &new{2012-04-29 (日) 02:14:27}; -- 1' -- [[1]] &new{2012-04-29 (日) 02:14:28}; - 1 -- [[1]] &new{2012-04-29 (日) 02:14:29}; - 1 -- [[1]] &new{2012-06-29 (金) 17:07:07}; - 1 -- [[1]] &new{2012-06-29 (金) 17:07:10}; - 1 -- [[-1']] &new{2012-06-29 (金) 17:07:11}; -- 1' -- [[1]] &new{2012-06-29 (金) 17:07:12}; - 1 -- [[1]] &new{2012-06-29 (金) 17:07:14}; - 1 -- [[1]] &new{2012-07-13 (金) 18:13:15}; - 1 -- [[1]] &new{2012-07-13 (金) 18:13:18}; - 1 -- [[-1']] &new{2012-07-13 (金) 18:13:19}; -- 1' -- [[1]] &new{2012-07-13 (金) 18:13:21}; - 1 -- [[1]] &new{2012-07-13 (金) 18:13:22}; - 1 -- [[1]] &new{2012-08-26 (日) 21:06:26}; - 1 -- [[1]] &new{2012-08-26 (日) 21:06:29}; - 1 -- [[-1']] &new{2012-08-26 (日) 21:06:30}; -- 1' -- [[1]] &new{2012-08-26 (日) 21:06:31}; - 1 -- [[1]] &new{2012-08-26 (日) 21:06:33}; - 1 -- [[1]] &new{2013-10-21 (月) 11:58:29}; - 1 -- [[1]] &new{2013-10-21 (月) 11:58:39}; - 1 -- [[-1']] &new{2013-10-21 (月) 11:58:44}; #comment_nospam - 1 -- [[1]] &new{2013-10-21 (月) 11:58:32}; - 1 -- [[1]] &new{2012-08-26 (日) 21:06:27}; - 1 -- [[1]] &new{2012-07-13 (金) 18:13:16}; - 1 -- [[1]] &new{2012-06-29 (金) 17:07:08}; - 1 -- [[1]] &new{2012-04-29 (日) 02:14:24}; - 1 -- [[1]] &new{2012-03-12 (月) 20:58:52}; #vote(参考になった[0],ふつう[0],参考にならなかった[0]) ~ ~ ~ *(参考)SqlDataSourceコントロールを利用して実現した場合 [#tfaf915e] カレンダ コントロールとSqlDataSourceコントロールを利用して、スケジュール情報 をカレンダに表示した事例である。コードの記述が少なくて実現出来るのが特徴。 10/08/10 【sqlCalCellDisp_sqlDS.aspx】 <%@ Page Language="VB" ContentType="text/html" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.Common" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="Server"> ' それぞれの日付セルをレンダリングするタイミングで実行 Sub cal_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) sds.SelectParameters.Clear() sds.SelectParameters.Add("sdate", e.Day.Date.ToString("yyyy/MM/dd")) Dim objRd As IDataReader = sds.Select(DataSourceSelectArguments.Empty) ' 取得したスケジュール情報を基に ' LiteralControl(固定文字列)を生成し、 ' 日付セル(e.Call)配下のコントロールとして追加 Do While objRd.Read() e.Cell.Controls.Add(New LiteralControl("<br />" & String.Format("{0}〜{1}:{2}", objRd.GetString(3), objRd.GetStr ing(4), objRd.GetString(1)))) Loop End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>スケジュールをカレンダー上に表示する</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Calendar id="cal" runat="server" DayHeaderStyle-BackColor="#FFCC66" onDayRender="cal_DayRender" ShowGridLines="true" BorderWidth="3" BorderColor="Black" Font-Name="Verdana" Font-Size="10px" TitleStyle-BackColor="#FFCC66" TitleStyle-Font-Size="12px" TitleStyle-Font-Bold="true" DayStyle-VerticalAlign="Top" DayStyle-Height="50px" DayStyle-Width="14%" SelectedDayStyle-BackColor="Navy" ShowNextPrev="True" NextPrevFormat="FullMonth"> <SelectedDayStyle BackColor="#CC5533" /> </asp:Calendar> <asp:SqlDataSource ID="sds" runat="server" ConnectionString="<%$ ConnectionStrings:MySqlServerDB %>" DataSourceMode="DataReader" ProviderName="<%$ ConnectionStrings:MySqlServerDB.ProviderName %>" SelectCommand="SELECT [ID], [title], [sdate], [stime], [etime] FROM [schedule01] WHERE ([sdate] = @sdate) ORDER B Y [stime] ASC"> </asp:SqlDataSource> <br /> <br /> </div> </form> </body> </html> - 1 -- [[1]] &new{2012-03-12 (月) 20:59:14}; - 1 -- [[1]] &new{2012-03-12 (月) 20:59:17}; - 1 -- [[-1']] &new{2012-03-12 (月) 20:59:18}; -- 1' -- [[1]] &new{2012-03-12 (月) 20:59:19}; - 1 -- [[1]] &new{2012-03-12 (月) 20:59:20}; - 1 -- [[1]] &new{2012-04-29 (日) 02:14:45}; - 1 -- [[1]] &new{2012-04-29 (日) 02:14:48}; - 1 -- [[-1']] &new{2012-04-29 (日) 02:14:49}; -- 1' -- [[1]] &new{2012-04-29 (日) 02:14:50}; - 1 -- [[1]] &new{2012-04-29 (日) 02:14:51}; - 1 -- [[1]] &new{2012-06-29 (金) 17:07:33}; - 1 -- [[1]] &new{2012-06-29 (金) 17:07:36}; - 1 -- [[-1']] &new{2012-06-29 (金) 17:07:37}; -- 1' -- [[1]] &new{2012-06-29 (金) 17:07:38}; - 1 -- [[1]] &new{2012-06-29 (金) 17:07:39}; - 1 -- [[1]] &new{2012-07-13 (金) 18:13:41}; - 1 -- [[1]] &new{2012-07-13 (金) 18:13:44}; - 1 -- [[-1']] &new{2012-07-13 (金) 18:13:45}; -- 1' -- [[1]] &new{2012-07-13 (金) 18:13:46}; - 1 -- [[1]] &new{2012-07-13 (金) 18:13:47}; - 1 -- [[1]] &new{2012-08-26 (日) 21:06:50}; - 1 -- [[1]] &new{2012-08-26 (日) 21:06:52}; - 1 -- [[-1']] &new{2012-08-26 (日) 21:06:53}; -- 1' -- [[1]] &new{2012-08-26 (日) 21:06:54}; - 1 -- [[1]] &new{2012-08-26 (日) 21:06:56}; - 1 -- [[1]] &new{2013-10-21 (月) 12:00:05}; - 1 -- [[1]] &new{2013-10-21 (月) 12:00:10}; - 1 -- [[-1']] &new{2013-10-21 (月) 12:00:13}; -- 1' -- [[1]] &new{2013-10-21 (月) 12:00:18}; - 1 -- [[1]] &new{2013-10-21 (月) 12:00:35}; #comment_nospam - 1 -- [[1]] &new{2013-10-21 (月) 12:00:08}; - 1 -- [[1]] &new{2012-08-26 (日) 21:06:51}; - 1 -- [[1]] &new{2012-07-13 (金) 18:13:43}; - 1 -- [[1]] &new{2012-06-29 (金) 17:07:34}; - 1 -- [[1]] &new{2012-04-29 (日) 02:14:47}; - 1 -- [[1]] &new{2012-03-12 (月) 20:59:15}; #vote(参考になった[0],ふつう[0],参考にならなかった[0])