title: How to set custom column header to a datagridview and display datatable records?
body: <p>QI want to display queried records from SQl Server which are in a table with custom column headers. How can I do it ?</p>
  
  <p>My querying function is as below</p>
  
  <pre><code>        private DataTable GetRecords(int QID, DateTime FromDate, DateTime ToDate)
      {
          SqlConnection myConn = new SqlConnection(ConfigurationManager.ConnectionStrings["CONNSTRING"].ConnectionString);
  
          // Create the command and set its properties.
          SqlCommand command = new SqlCommand();
          command.Connection = myConn;
          command.CommandText = "sp_GetRecords";
          command.CommandType = CommandType.StoredProcedure;
  
          // Add the input parameter and set its properties.
          SqlParameter parameter1 = new SqlParameter();
          parameter1.ParameterName = "@QID";
          parameter1.SqlDbType = SqlDbType.Int; 
          parameter1.Direction = ParameterDirection.Input;
          parameter1.Value = QID;
  
          SqlParameter parameter2 = new SqlParameter();
          parameter2.ParameterName = "@FromDate";
          parameter2.SqlDbType = SqlDbType.DateTime;
          parameter2.Direction = ParameterDirection.Input;
          parameter2.Value = FromDate;
  
          SqlParameter parameter3 = new SqlParameter();
          parameter3.ParameterName = "@ToDate";
          parameter3.SqlDbType = SqlDbType.DateTime;
          parameter3.Direction = ParameterDirection.Input;
          parameter3.Value = ToDate;
          // Add the parameter to the Parameters collection. 
          command.Parameters.Add(parameter1);
          command.Parameters.Add(parameter2);
          command.Parameters.Add(parameter3);
           myConn.Open();
           SqlDataReader GetAgentTransactions = command.ExecuteReader();
           DataTable dt = new DataTable();
           dt.Load(GetAgentTransactions);             
           GetAgentTransactions.Close();
           myConn.Close();
           return dt;
  
      }
  </code></pre>
  
  <p>To bind and display in datagridview, I have the following on a display button click event.</p>
  
  <pre><code> protected void btnShow_Click(object sender, EventArgs e)
      {
         DataTable table = new DataTable();
         table = GetRecords(1, Convert.ToDateTime(txtFromDate.Text.Trim()), Convert.ToDateTime(txtToDate.Text.Trim()));
         datagridview.DataSource = table;
         datagridview.DataBind();           
      }
         }
  </code></pre>
  
  <p>I want the returned records to be shown under the column headers as Sl. No, Name and Reg. Number. How can I do it ? Please help with a code example.</p>