By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,240 Members | 791 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,240 IT Pros & Developers. It's quick & easy.

How to Display Selected Dates from a Database in the Calendar Control

P: 21
How to Display Selected Dates from a Database in the Calendar Control event in asp.net using in C# coding(2010)..

I was taken one calender controller, and i want to display entire week details in "grid view" controller.

I just changed calender controller properties "selection mode" day,week option.

i want to retrieve the data from database.

Can any one please help me.
Nov 29 '11 #1
Share this Question
Share on Google+
5 Replies


Frinavale
Expert Mod 5K+
P: 9,731
I'm a little confused about what you're trying to accomplish.
If you want to use a Calendar Control in a GridView, add it to a Template Column and bind the calendar to the underlying source (that contains the date to select).

Like this:
(ASP.NET code)
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head runat="server">
  6.     <title></title>
  7. </head>
  8. <body>
  9.     <form id="form1" runat="server">
  10.     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
  11.         <Columns>
  12.             <asp:TemplateField HeaderText="Selected Days">
  13.                 <ItemTemplate>
  14.                     <asp:Calendar ID="Calendar1" runat="server" SelectedDate='<%#((DateTime)Eval("SelectedDate")).Date%>'
  15.                         VisibleDate='<%#Eval("SelectedDate")%>'></asp:Calendar>
  16.                 </ItemTemplate>
  17.             </asp:TemplateField>
  18.         </Columns>
  19.     </asp:GridView>
  20.     </form>
  21. </body>
  22. </html>
(C# code for the page)
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. namespace WebApplication1
  9. {
  10.     public partial class WebForm1 : System.Web.UI.Page
  11.     {
  12.         private System.Data.DataTable dataSource;
  13.  
  14.         protected void Page_Load(object sender, EventArgs e)
  15.         {
  16.             if (Session["dataSource"] == null)
  17.             {
  18.                 dataSource = GenerateDataSource();
  19.                 Session["dataSource"] = dataSource;
  20.             }
  21.             else
  22.             {
  23.                 dataSource = (System.Data.DataTable)Session["dataSource"];
  24.             }
  25.  
  26.         }
  27.  
  28.         void Page_PreRender(object sender, EventArgs e)
  29.         {
  30.  
  31.             GridView1.DataSource = dataSource;
  32.             GridView1.DataBind();
  33.         }
  34.  
  35.         private System.Data.DataTable GenerateDataSource()
  36.         {
  37.             System.Data.DataTable dt = new System.Data.DataTable();
  38.             dt.Columns.Add(new System.Data.DataColumn("SelectedDate",typeof(DateTime)));
  39.  
  40.             for (int i = 0; i < 10; i++)
  41.             {
  42.                 if (i % 2 == 0)
  43.                 {
  44.                     DateTime d = DateTime.Now;
  45.                     d = d.AddDays(i);
  46.                     d = d.AddMonths(i);
  47.                     System.Data.DataRow dr = dt.NewRow();
  48.                     dr[0] = d;
  49.                     dt.Rows.Add(dr);
  50.                 }
  51.  
  52.             }
  53.  
  54.             return dt;
  55.         }
  56.  
  57.  
  58.     }
  59. }
-Frinny
Dec 5 '11 #2

P: 21
Hi,
Attached the image, please find that, in that image there is a "add client" option is there , when we click that button more tables will be adding(Dynamically adding the rows). There is a calender tool is also there, if we click any particular date that details should be display in grid view rows.That text boxes should accepts only numeric values.(Characters never display).

Dec 6 '11 #3

P: 21
i tried but getting this error!
Compiler Error Message: CS1061: 'ASP.webform1_aspx' does not contain a definition for 'GridView1_SelectedIndexChanged' and no extension method 'GridView1_SelectedIndexChanged' accepting a first argument of type 'ASP.webform1_aspx' could be found (are you missing a using directive or an assembly reference?)
Dec 6 '11 #4

P: 21
U r code is working, but my task is different..

i attached the image in that image there is a "add client" option is there , when we click that button more tables will be adding(Dynamically adding the rows). There is a calender tool is also there, if we click any particular date that details should be display in grid view rows.That text boxes should accepts only numeric values.(Characters never display).
Dec 6 '11 #5

Frinavale
Expert Mod 5K+
P: 9,731
Well handle Calendar's SelectionChanged Event and implement the logic required for retrieving the information to display based on the selected date in the calendar control...

I can't figure out how select a day in the calendar becomes a bunch of numbers for a week (which is what I'm assuming you are displaying in the GridView)...but I'm sure it makes sense to you
Dec 6 '11 #6

Post your reply

Sign in to post your reply or Sign up for a free account.