I am trying to add a search header within my gridview, however when I render the grdiview databound method, I get a blank page output on the client-side.
I am little unclear where I may be going wrong. I have also debugged the my databound gridview event and the rows parameter is shown to be null. However, I have tested my 'bindgrid' method and this does work (outputs user table).
private void BindGrid()
{
string strConnString = ConfigurationManager.ConnectionStrings["cdwConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select top 20 u.[uID], u.[uForenames], u.[uSurname], u.[uCompany], u.[uEmailAddress], s.[sStartDate] from [dbo].[UserDetails]";
cmd.Connection = con;
con.Open();
GridView3.DataSource = cmd.ExecuteReader();
GridView3.DataBind();
con.Close();
}
}
}
protected void OnDataBound(object sender, EventArgs e)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
if (row == null) { return; }
else
{
if (GridView3.Rows.Count > 0)
{
for (int i = 0; i < GridView3.Columns.Count; i++)
{
TableHeaderCell cell = new TableHeaderCell();
TextBox txtSearch = new TextBox();
txtSearch.Attributes["placeholder"] = GridView3.Columns[i].HeaderText;
txtSearch.CssClass = "search_textbox";
cell.Controls.Add(txtSearch);
row.Controls.Add(cell);
}
GridView3.HeaderRow.Parent.Controls.AddAt(1, row);
}
}
}
<asp:gridView ID="GridView3" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
runat="server" AutoGenerateColumns="false" OnDataBound="OnDataBound">
</asp:gridView>
Any further advice would be very much appreciated. Many thanks.