I am trying to display a database table in a DataGrid but the DataGrid isn't displaying. All I have is a textbox and under it I want the DataGrid to display the table. The textbox is displaying but the DataGrid isn't.
<table>
<tbody>
<tr>
<td class="Header">Public Holiday Date</td>
<td>
<asp:TextBox runat="server" ID="txtDate" rel="datepicker" ></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:DataGrid runat="server" id="dataGridView1" AutoGenerateColumns="true"></asp:DataGrid>
</td>
</tr>
</tbody>
</table>
The code for getting the data from the database:
private DataSet GetBankHolidays()
{
DataSet ds = new DataSet();
string sql = "proc_GetAllCustomers";
string query = "SELECT BankHol FROM bankholidays";
DataTable dt = new DataTable();
using (MySql.Data.MySqlClient.MySqlDataAdapter adapter = new MySql.Data.MySqlClient.MySqlDataAdapter(sql, DataUtils.ConnectionStrings["TAT"]))
{
adapter.SelectCommand.CommandType = CommandType.Text;
adapter.SelectCommand.CommandText = query;
adapter.Fill(dt);
ds.Tables.Add(dt);
dataGridView1.DataSource = dt;
dataGridView1.DataBind();
}
return ds;
}
And I'm calling this method in the page load:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GetBankHolidays();
}
}