title: Grid view to display date format in MM-DD-YYYY format
body: <p>I have a gridview to display date on button click depending on the checkbox(s) selected. I have used string concatenation to fetch data to manage dynamic changes at the UI. Currently, it displays in this format - <code>MM-DD-YYYY 12:00:00 AM</code>, by default but I need it in <code>MM-DD-YYYY</code> format.</p>
  
  <p>With <code>BoundField, DataFormatString="{0:d}" HtmlEncode="False"</code>, I get the desired output but I can't build the dynamic SQL connection string. I have referred the tutorials and websites but most have them have provided solution with fixed SQL query or by using Gridview's "Choose Data Source" option. In my case, since its dynamic query, I can't Choose Data Source, I guess. </p>
  
  <p>Is it possible to set a particular column's property of gridview to display the desired format.? Please suggest. Kindly share your thoughts with sample code (will be more helpful). </p>
  
  <p>The code is as follows. The current output is attached.</p>
  
  <p>Code:</p>
  
  <pre><code>DataTable GetData(int Count)
  {
      DataTable dt = new DataTable();
      string query = "SELECT [NAME], [Date], Duration FROM dbo.OnLeaveDetails WHERE @User = Username AND ";
      string whereClause = "[Leave Type] = ";
  
      if(CheckBox1.Checked)
          query += whereClause + "@" + &lt;TYPE1&gt;;
      ....
      ....
  
      Command = new SqlCommand(query, Conn);
  
      try
      {
          Conn.Open();
          Command.Parameters.Add("User", SqlDbType.NVarChar).Value = Username;
  
          if (CheckBox1.Checked)
              Command.Parameters.Add(&lt;TYPE&gt;, SqlDbType.NVarChar).Value = LeaveType[0];
          ....
          ....
  
          SqlDataAdapter adpt = new SqlDataAdapter(Command);
          adpt.Fill(dt);
          Conn.Close();
          return dt;
      }
      catch ()
      {....}
  }
  
  protected void Submit_Click(object sender, EventArgs e)
  {
      GridView1.DataSource = GetData(count);
      GridView1.DataBind();
  }
  </code></pre>