[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Use the Calendar Conrtol to populate datagrid with event data

Posted on 2006-07-06
5
Medium Priority
?
419 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 1200 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 have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

656 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