Solved

Use the Calendar Conrtol to populate datagrid with event data

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

707 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