Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# MySQL
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 26-Mar-13 1:31am
navin ks1.4K
Edited 26-Mar-13 1:54am
ProgramFOX127.8K
v2
Comments
onurag19 at 26-Mar-13 6:42am
   
Is Gridview Visibility true?
navin ks at 26-Mar-13 6:43am
   
yes
onurag19 at 26-Mar-13 6:46am
   
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
Try This.
navin ks at 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
onurag19 at 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];.
Maciej Los at 26-Mar-13 6:56am
   
GridView is a control for WinForms or for WebControls?
navin ks at 26-Mar-13 7:09am
   
web
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try to set:
AutoGenerateColumns[^] to TRUE and use: EmptyDateText[^] property to display text when gridview's data source does not contain any records.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 299
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 230
3 Aajmot Sk 191
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100