Solved

Use the Calendar Conrtol to populate datagrid with event data

Posted on 2006-07-06
5
404 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
call function 8 40
401 - Error 6 24
asp.net bundle 8 33
Jquery autocomplete 10 19
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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now