Reputation: 41
I have dropdowns and a button in a webpage. After this button click Im getting the griview with page numbers. But when I click on any page number the gridview is disappearing (Initially my panel is invisible).I have tried many solutions, but non of them working. can you check whts wrong in the code.
<asp:GridView ID="gv_AllEmployees" runat="server"
class="table table-striped table-bordered table-hover"
AutoGenerateColumns="False"
OnRowDataBound="gv_AllEmployees_RowDataBound"
AllowPaging="true" PageSize="15"
OnPageIndexChanging="gv_AllEmployees_PageIndexChanging">
protected void Page_Load(object sender, EventArgs e)
{
dt_Departments = ViewsLogic.GetDepartments();
if (!IsPostBack)
{
ddlDepartment.DataSource = dt_Departments;
ddlDepartment.DataTextField = "DepartName";
ddlDepartment.DataValueField = "DeptId";
ddlDepartment.DataBind();
ddlDepartment.Items.Insert(0, new ListItem("Select Department", "Select Department"));
ListItem lst = new ListItem("All Departments", "-1");
ddlDepartment.Items.Insert(ddlDepartment.Items.Count, lst);
this.BindAllEmpLog();
//gv_AllEmployees.Visible = true;
}
}
protected void gv_AllEmployees_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gv_AllEmployees.PageIndex = e.NewPageIndex;
BindAllEmpLog();
}
void BindAllEmpLog()
{
dt_AllEmpLog = ViewsLogic.GetAllEmpLog(date.Date);
//gv_AllEmployees.PageIndex = newPageIndex;
gv_AllEmployees.DataSource = dt_AllEmpLog;
gv_AllEmployees.DataBind();
pnl_AllEmployees.Visible = true;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
pnl_Grids.Visible = false;
lblError.Visible = false;
pnl_AllEmployees.Visible = false;
date = Convert.ToDateTime(txtDate.Text);
if (ddlDepartment.SelectedIndex < 1)
{
pnl_Grids.Visible = false;
pnl_AllEmployees.Visible = false;
lblError.Text = "Please Select a department from the list";
lblError.Visible = true;
}
else if (ddlDepartment.SelectedIndex == ddlDepartment.Items.Count - 1) //If last item Selected
{
BindAllEmpLog();
}
else
{
Upvotes: 0
Views: 1067
Reputation: 41
Thank you guys. I found the solution. I was not getting the data in the datatable on the index change because of the following line. I copied this line in the BindAllEmpLog() method. then it is working fine.
date = Convert.ToDateTime(txtDate.Text);
Upvotes: 1