Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6210753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:12:57+00:00 2026-05-24T06:12:57+00:00

I really can’t seem to nail down what I need to accomplish my task.

  • 0

I really can’t seem to nail down what I need to accomplish my task. I have a DataGrid in asp.net in VS2010 this displays data from a SQL database , in one of these fields is a “StartDate”.

Also I have a simple Calendar running . What I would like is to be able to update my DataGrid by passing it the selected date and using that as the “StartDate” to call a selection on the DataGrid , so only records with that start date will appear.

I have looked on-line but the examples are very old or are a bit confusing .

If anyone can layout the steps (if possible sample code) involved to achieve this i would be grateful or any resources or examples you have come across though I have searched for a while, hence the post!.

Thanks.

What i have currently is

   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            Calendar1.VisibleDate = DateTime.Today;
            strConn = @"Data Source=PC88;Initial Catalog=Bookings;Integrated Security=True";    
            mycn = new SqlConnection(strConn);
            myda = new SqlDataAdapter("Select * FROM Bookings", mycn);
            myda.Fill(ds, "Table");
        }
        else 
        {
           // CalendarChange();
            Calendar1.VisibleDate = DateTime.Today;
            strConn = @"Data Source=PC88;Initial Catalog=Bookings;Integrated Security=True";    
            mycn = new SqlConnection(strConn);
            myda = new SqlDataAdapter("Select * FROM Bookings", mycn);
            myda.Fill(ds, "Table");

        }

    }

    protected void CalendarDRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
    {
        // If the month is CurrentMonth
        if (!e.Day.IsOtherMonth)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if ((dr["Start"].ToString() != DBNull.Value.ToString()))
                {
                    DateTime dtEvent = (DateTime)dr["Start"];
                    if (dtEvent.Equals(e.Day.Date))
                    {
                        e.Cell.BackColor = Color.PaleVioletRed;
                    }
                }
            }
        }
        //If the month is not CurrentMonth then hide the Dates
        else
        {
        e.Cell.Text = "";
        }
        }


        private void Calendar1_SelectionChanged(object sender, System.EventArgs e)
        {
        myda = new SqlDataAdapter("Select * from Bookings where Start ='" + Calendar1.SelectedDate.ToString() + "'", mycn);
        dsSelDate = new DataSet();
        myda.Fill(dsSelDate, "AllTables");
        if (dsSelDate.Tables[0].Rows.Count == 0 )
        {
        GridView1.Visible = false;
        }
        else
        {
        GridView1.Visible = true;
        GridView1.DataSource = dsSelDate;
        GridView1.DataBind (); 
        }
      } 
    }

What am i doing wrong?.

EDIT__

Finally it works , Here is my code if anyone has similar issue/requirement.

   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!IsPostBack)
            {

                Calendar1.VisibleDate = DateTime.Today;
                strConn = @"Data Source=BBC-PC-S054683;Initial Catalog=Bookings;Integrated Security=True";
                mycn = new SqlConnection(strConn);
                myda = new SqlDataAdapter("Select * FROM Bookings", mycn);
                myda.Fill(ds, "Table");

            }
            else
            { // CalendarChange();
                Calendar1.VisibleDate = DateTime.Today;
                strConn = @"Data Source=PC-Name;Initial Catalog=Bookings;Integrated Security=True";
                mycn = new SqlConnection(strConn);
                myda = new SqlDataAdapter("Select * FROM Bookings", mycn);
                myda.Fill(ds, "Table");

            }

            BindGrid();
        }
    }
    private DataTable GetRecords()
    {
        SqlConnection conn = new SqlConnection(strConnection);
        conn.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "Select * from Bookings";
        SqlDataAdapter dAdapter = new SqlDataAdapter();
        dAdapter.SelectCommand = cmd;
        DataSet objDs = new DataSet();
        dAdapter.Fill(objDs);
        return objDs.Tables[0];


    }

    public void Calendar1_SelectionChanged(object sender, System.EventArgs e)
    {

        String Date = Calendar1.SelectedDate.ToLongDateString();
        SqlConnection con = new SqlConnection(strConnection);//put connection string here
        SqlCommand objCommand = new SqlCommand("SELECT * FROM Bookings where Date = '" + Date + "'", con);//let MyTable be a database table
        con.Open();
        SqlDataReader dr = objCommand.ExecuteReader(); 

        GridView.DataSource = dr;
        GridView.DataBind();



                    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:12:58+00:00Added an answer on May 24, 2026 at 6:12 am

    You need to filter your DataGridView.

    try
    {
        myDataSet = new DataSet();
        myDataSet.CaseSensitive = true;
    
        DataAdapter.SelectCommand.Connection = myConnection;
        DataAdapter.TableMappings.Clear();
        DataAdapter.TableMappings.Add("Table", "TableName");
        DataAdapter.Fill(myDataSet);
    
        myDataView = new DataView(myDataSet.Tables["TableName"], "TIMESTAMP >= '" + 
        Convert.ToDateTime(fromDate) + "' AND TIMESTAMP <= '" + 
        Convert.ToDateTime(toDate) + "'", "TIMESTAMP", DataViewRowState.CurrentRows);
    
        dgv.DataSource = myDataView;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    

    TIMESTAMP is a column in my DataGridView.
    Note: This is just a code snippet!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Distributing ASP.NET user controls across different projects can be really useful when you want
Can anyone help with this I really can't see what is wrong. I have
Can I really and truly trust .NET to initialize fields (like ints, structs and
I've got a really simple rails question here but I can't seem to find
I really can't work out how to best do this, I can do fairly
I really can't believe I couldn't find a clear answer to this... How do
I really can't wrap my mind around this: Previously I couldn't get Framebuffers to
simple question really (can hazard a guess but just need to make sure), Just
I really can't explain this one properly, so here's a screenshot: How do I
Sorry everyone, I really can't find any better title for my question. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.