0

我正在使用 ASP.Net 4.5 ,并面临一个关于使用“选择方法”的网格视图数据绑定的问题。

网格也能够在自定义分页上绑定数据。

问题在于过滤数据。我有一个 asp 按钮,通过单击它,我可以使用存储的 proc 获取过滤数据。但是这次网格无法调用我在 aspx 页面中提到的 SelectMethod 中该网格的方法。

<asp:GridView ID="gEmployee" runat="server"

   AutoGenerateColumns="False"

   OnRowCommand="gEmployee_Command" CellPadding="4"

   OnRowDataBound="gEmployee_RowDataBound"

   AllowCustomPaging="true" PageSize="10" PagerSettings-Visible="false"

   CssClass="mGrid"

   AllowSorting ="true"

   AlternatingRowStyle-CssClass="alt"

ItemType="ModelEntityLayer.ClsEmployee"  SelectMethod="BindGrid" 

   OnSorting ="gEmployee_OnSorting"  HeaderStyle-Wrap="false" DataKeyNames="PropClockNumber" >

上面的代码显示了我为网格视图设置的属性。

public IQueryable<ClsEmployee> BindGrid()


{

    int intTotalPages = 0;

    objBALEmployee = new ClsEmployeeBAL();

    List<ClsEmployee>  employee = null;

    if ((string)Session["QueryResult"] != null)

    {

        employee = objBALEmployee.GetPageWiseData(gEmployee.PageIndex, gEmployee.PageSize, ViewState["SortExpression"] != null ? ViewState["SortExpression"].ToString() : ViewState["ClockNumber"].ToString(),  ViewState["SortOrder"] != null ? ViewState["SortOrder"].ToString() : "asc", ref intTotalPages, ((string)Session["QueryResult"]));

        Session.Remove("QueryResult");

    }

    else

    {

        if (Convert.ToInt32(ViewState["IsEditSearch"]) != 1)

        {

            employee = objBALEmployee.GetPageWiseData(gEmployee.PageIndex, ViewState["SortExpression"] != null ? ViewState["SortExpression"].ToString() : ViewState["ClockNumber"].ToString(),  ViewState["SortOrder"] != null ? ViewState["SortOrder"].ToString() : "asc", gEmployee.PageSize, ref intTotalPages);

        }

        else

        {

            employee = objBALEmployee.GetPageWiseData(gEmployee.PageIndex, gEmployee.PageSize, ViewState["SortExpression"] != null ? ViewState["SortExpression"].ToString() : ViewState["ClockNumber"].ToString(),  ViewState["SortOrder"] != null ? ViewState["SortOrder"].ToString() : "asc", ref intTotalPages, dlEmployee.SelectedValue+" = '"+txtSearch.Text.Trim()+"'");

        }

    }

    var lstEmployee = employee.AsQueryable();

    if (intTotalPages > 0)

    {

        CustomPager.TotalPages =  intTotalPages %gEmployee.PageSize == 0 ? intTotalPages /gEmployee.PageSize : intTotalPages / gEmployee.PageSize + 1;

        CustomPager.Visible = true;

        lblNoRecordsFound.Visible = false;

        NoRecords.Visible = false;

    }

    else

    {

        CustomPager.Visible = false;

        lblNoRecordsFound.Visible = true;

        NoRecords.Visible = true;

    }

    ExportData1.DisableBtn(gEmployee);

    ExportData.ExportCheck = false;

    return lstEmployee;

}

上面的代码显示了bindGrid我为网格中的 selectMethod 设置的方法。

protected void btnGo_Click(对象发送者,EventArgs e)

{

    ViewState["IsEditSearch"] = "1";

    hiddenSearchField.Value = dlEmployee.SelectedValue;

    hiddenSearchValue.Value = txtSearch.Text.Trim();

    gEmployee.SelectMethod = "BindGrid";

}

上面的代码是为按钮单击编写的。

尽管我gEmployee.SelectMethod = "BindGrid";再次编写了点击代码,但BindGrid并没有被解雇。所以我无法将我新过滤的数据绑定到网格。

请指导我。

谢谢。

4

1 回答 1

2

我认为您需要btnGo_Click在网格上明确调用 DataBind() 的末尾添加一行:

protected void btnGo_Click(object sender, EventArgs e)
{
    ViewState["IsEditSearch"] = "1";
    hiddenSearchField.Value = dlEmployee.SelectedValue;
    hiddenSearchValue.Value = txtSearch.Text.Trim();
    gEmployee.SelectMethod = "BindGrid";

    gEmployee.DataBind();
}
于 2013-03-25T07:08:04.420 回答