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
Solved

Use the Calendar Conrtol to populate datagrid with event data

Posted on 2006-07-06
5
412 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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

791 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