在asp网页中单击按钮后,Gridview Paging无法正常工作

时间:2016-04-05 08:38:03

标签: c# asp.net

我在网页上有下拉菜单和一个按钮。在此按钮后单击我获取页面编号的griview。但是,当我点击任何页码时,gridview正在消失(最初我的面板是不可见的)。我尝试了很多解决方案,但没有解决方案。你可以检查代码中的错误。

 <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
    {

1 个答案:

答案 0 :(得分:1)

谢谢你们。我找到了解决方案。由于以下行,我没有在索引更改的数据表中获取数据。我在BindAllEmpLog()方法中复制了这一行。然后它工作正常。

date = Convert.ToDateTime(txtDate.Text);