Dear Stack Overflowers,
I have a gridview in the front end page and here it is in asp.net code:
<asp:GridView ID="grdManufact" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4"
GridLines="Horizontal" AllowPaging="True" OnRowDataBound="manufGridView_RowDataBound" EnableModelValidation="False" EnableSortingAndPagingCallbacks="True" HorizontalAlign="Center" OnSelectedIndexChanged="grdManufact_SelectedIndexChanged" OnPageIndexChanging="grdManufact_PageIndexChanging">
<Columns>
<asp:BoundField DataField="SrNo" HeaderText="SrNo" />
<asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:BoundField DataField="isModerated" HeaderText="Approved" />
<asp:BoundField />
Well that is the main part of it but it displays correctly and binds correctly upon page load. Whenever I change page to page 2 or 3 or whatever of the gridview, my gridview disappears! I have tried putting a breakpoint in the PageIndexChanging function but the breakpoint is not reached which tells me that the event is not even firing and yet the gridview just disappears. Here is my backend function Page Index Changing anyway:
protected void grdManufact_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdManufact.PageIndex = e.NewPageIndex;
BindGrid();
}
And the BindGrid() function used to bind the grid :
public void BindGrid()
{
string strConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString2"].ToString();
SqlConnection conn = new SqlConnection(strConnectionString); // Connect to database
conn.Open(); // Open Connection
string com = "select ManufacturerID as SrNo, ManufacturerName as Manufacturer, ManufacturerDescription as Description,isModerated From VehicleManufacturer";
SqlDataAdapter adpt = new SqlDataAdapter(com, conn); // Select all manufacturers in the table
DataTable dt = new DataTable(); // Create a new Data Table
adpt.Fill(dt); // Fill it with manufacturers
grdManufact.DataSource = dt; // Make the datasource of the manufacturer grid the new table
grdManufact.DataBind(); // Bind data for the grid
conn.Close(); // Close database connection. Disconnect
}
Here is my page load in case you wanted that too:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) // If this is the first time loading the page through postback BindGrid(); // Bind the Manufacturers to the gridview else { ClientScript.GetPostBackEventReference(this, string.Empty); if (Request.Form["__EVENTTARGET"] == "Button2_Click") { //call the method btnDelete_Click(this, new EventArgs()); } } }
Can you please tell me what I am doing wrong or point me in the right direction to fix this please?