Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void BindDates()
        {

            DateTime FromDate = DateTime.Now.ToUniversalTime().AddHours(5.5);

            TxtFromDate.Text = FromDate.ToString("yyyy/MM/dd");

            DateTime ToDate = DateTime.Now.ToUniversalTime().AddHours(5.5);

            TxtToDate.Text = ToDate.ToString("yyyy/MM/dd");

        }
        protected void databind()
        {
            string[] strFromDate = TxtFromDate.Text.Split('/');
            string[] strToDate = TxtToDate.Text.Split('/');

            DateTime fromDate = Convert.ToDateTime(strFromDate[1] + '/' + strFromDate[2] + '/' + strFromDate[0]);
            DateTime toDate = Convert.ToDateTime(strToDate[1] + '/' + strToDate[2] + '/' + strToDate[0]);
            con.Open();
            MySqlCommand com = new MySqlCommand("SELECT * FROM processeddata_table WHERE dialdate BETWEEN '" + fromDate + "' AND '" + toDate + "' ", con);
            {
                DataTable ds = new DataTable();
                MySqlDataAdapter da = new MySqlDataAdapter(com);
                da.Fill(ds);
                GridView1.DataSource = ds;
                GridView1.DataBind();
                con.Close();
                da.Dispose();
                ds.Dispose();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            databind();
        }
    }
[Edit]Code block added[/Edit]
Posted
Updated 26-Mar-13 0:54am
v2
Comments
[no name] 26-Mar-13 6:42am    
Is Gridview Visibility true?
navin ks 26-Mar-13 6:43am    
yes
[no name] 26-Mar-13 6:46am    
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
Try This.
navin ks 26-Mar-13 6:49am    
Error 1 'System.Data.DataTable' does not contain a definition for 'Tables' and no extension method 'Tables' accepting a first argument of type 'System.Data.DataTable' could be found (are you missing a using directive or an assembly reference?) F:\navin\dbdates\dbdates\Default.aspx.cs 46 43 dbdates
[no name] 26-Mar-13 6:52am    
Run the query on the Sql Editor or whichever you are using only query check if data exists or not.
And remove the ds.Tables[0];.

When there is no data the control is not visible.
You have to set the empty data temple to view the grid when there is no data.

First, make sure you are getting some data when using the given query.
 
Share this answer
 
Try to set:
AutoGenerateColumns[^] to TRUE and use: EmptyDateText[^] property to display text when gridview's data source does not contain any records.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900