I have a gridview, on the each column i want Search to implemented. I have implemented the code in the other aspx page and it is working fine. But when I implement here, the page is giving me error as Object reference not set to instance of an object. Please see the code of RowDataBound
of GridView.
<asp:GridView ID="grdPostData" runat="server" Width="100%" border="1" Style="border: 1px solid #E5E5E5;" CellPadding="3" AutoGenerateColumns="False" AllowPaging="true" PageSize="10" CssClass="hoverTable" OnPageIndexChanging="grdPostData_PageIndexChanging" OnRowDataBound="grdPostData_RowDataBound">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:BoundField DataField="cat_id" HeaderText="Title" ItemStyle-Width="50" ControlStyle-CssClass="k-grid td" Visible="false" />
<asp:BoundField DataField="ngo_id" HeaderText="Title" ItemStyle-Width="50" ControlStyle-CssClass="k-grid td" Visible="false" />
<asp:BoundField DataField="title" HeaderText="Title" ItemStyle-Width="50" ControlStyle-CssClass="k-grid td" />
<asp:BoundField DataField="description" HeaderText="Description" ItemStyle-Width="50" ControlStyle-CssClass="k-grid td" />
<asp:TemplateField HeaderText="Post Category" ItemStyle-Width="50">
<ItemTemplate>
<asp:DropDownList ID="ddlPostCategory" AppendDataBoundItems="true" runat="server"
AutoPostBack="True">
<asp:ListItem Text="Select" Value="0"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="active" HeaderText="Active" ItemStyle-Width="30" ControlStyle-CssClass="k-grid td" />
</Columns>
</asp:GridView>
Also see the CS code for the same:-
protected void grdPostData_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
for (int i = 0; i < grdPostData.Columns.Count; i++)
{
TableHeaderCell cell = new TableHeaderCell();
TextBox txtSearch = new TextBox();
txtSearch.Attributes["placeholder"] = grdPostData.Columns[i].HeaderText;
txtSearch.CssClass = "form-control HaydaBre";
cell.Controls.Add(txtSearch);
row.Controls.Add(cell);
}
grdPostData.HeaderRow.Parent.Controls.AddAt(1, row);
}
I am getting the mentioned error at
grdPostData.HeaderRow.Parent.Controls.AddAt(1, row);
Tried debugging the RowDataBound
Command but, it is not getting inside the above mentioned line. Please help. Also let me know if you need anything else.