Solved

Use the Calendar Conrtol to populate datagrid with event data

Posted on 2006-07-06
5
413 Views
Last Modified: 2012-05-05
I have an asp.net page with a calendar control and a datagrid.   I would like to get the datagrid to populate with the event information for the selected day.  For example if the user selects 7/6/06 from the calendar, all events scheduled for 7/6 will populate in the datagrid.  

I have created and filled a dataset during form_load (using VB) with the entire events table, but I can't figure out how to display only the dates I need and bind it to the datagrid.  Any help would be appreciated.
0
Comment
Question by:nmwilliams
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 300 total points
ID: 17056188
something like this -  
ps. the only thing is if you are filling the dataset in another method then you will have to persist the dataset into a session variable so that you can use it in the calendar SelectionChanged method. Or just get the data in the SelectionChanged method... then you can use sql with the date filter to get only specific records for the date.

current way :
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        DateTime dt = this.Calendar1.SelectedDate;
        DataSet ds = new DataSet();
        //fill the dataset - you must decide to use an existing dataset or get the records here from the db then you can build an sql command with the right date selected
        // use database specific dateformat
        ds.Tables["tablename"].DefaultView.RowFilter = "DateFieldinData = " + dt.ToString("yyyy-MM-dd HH:mm:ss");

        this.GridView1.DataSource = ds.Tables["tablename"].DefaultView;
        this.GridView1.DataBind();
    }


or get the specific data

    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        DateTime dt = this.Calendar1.SelectedDate;
        DataSet ds = new DataSet();

        string strcon = SqlDataSource1.ConnectionString;

        System.Data.SqlClient.SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand("SELECT ProductID, ProductName FROM products where dateordered > @dateparam", new System.Data.SqlClient.SqlConnection(strcon));
        sqlCmd.Parameters.Add("@dateparam", SqlDbType.VarChar).Value = dt.ToString("yyyy-MM-dd HH:mm:ss");

        System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter();
        sda.SelectCommand = sqlCmd;
        DataSet ds = new DataSet();
        sda.Fill(ds);

        this.GridView2.DataSource = ds;
        this.GridView2.DataBind();

    }

hope this helps
0
 

Author Comment

by:nmwilliams
ID: 17061216
I tried it exactly as you said, but I get the following error on the databind statement:

The IListSource does not contain any data sources.

Do you know what would cause this?
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 17064006
how are you populating the dataset, are you doing it in the calendar event handler and is every thing changed to your objects names?
are you using a session object to hold the dataset populated from somewhere else?
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 17064011
are you calling databind before all this happens somewhere else that might be triggering a databind prematurely on the grid?
0
 

Author Comment

by:nmwilliams
ID: 17075184
I was binding at design time and that was causing the error.  I fixed it after I posted.  Thanks so much for your help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question