0

我有一个查询,当用户提交搜索并gridview加载时运行。

我想分页,gridview并且通常会将我的网格放在LoadGrid(). 我的分页工作正常,一切都很好,直到我想查看GridView.

protected void btn_Search_Click(object sender, EventArgs e)
{
// Init()
// -----
pnl_Message.Visible = false;
lbl_message.Text = String.Empty;

// Clear grid of previous results
// ==============================
ResultsGridView.DataSource = null;
ResultsGridView.DataBind();

try
{
    using (var db = new dbDataContext())
    {
        // Check Fields
        // ------------
        if (txt_CustomerName.Text == string.Empty && txt_CCNo.Text == string.Empty &&
            txt_SwiftNo.Text == string.Empty && drp_Provider.SelectedValue == string.Empty)
        {
            lbl_message.Text += "* Please enter a search term";
            pnl_Message.Visible = true;
            pnl_Message.CssClass = "loginError";
            pnl_results.Visible = false;
        }

        // Search Database
        // ---------------
        if (lbl_message.Text == String.Empty)
        {
            var customer = txt_CustomerName.Text.Length > 1 ? txt_CustomerName.Text.Trim() :
            "Xcxcx";
            //var provider = drp_Provider.SelectedItem.Text.Trim();
            var concern = txt_CCNo.Text == "" ? 0 : Convert.ToInt32(txt_CCNo.Text);
            var swiftid = txt_SwiftNo.Text == "" ? 0 : Convert.ToInt32(txt_SwiftNo.Text);

            // Check which fields populated
            // ----------------------------
            var result =
                from c in db.tbl_Concerns
                where (c.ProviderId == Convert.ToInt32(drp_Provider.SelectedValue))
                    || (c.person_Fullname.Contains(customer))
                    || (c.SwiftId == swiftid)
                    || (c.ConcernId == concern)
                select new
                {
                    c.ConcernId,
                    Swift = c.SwiftId,
                    FullName = c.person_Fullname,
                    Provider = c.tbl_Provider.provider_Name,
                    Concern_Detail = c.tbl_RaisedConcern.RaisedConcernText,
                    DateFrom = c.concern_DateFrom,
                    DateTo = c.concern_DateTo
                };
            // If No Results
            // -------------
            if (!result.Any())
            {
                lbl_message.Text += "* No results match your search, please try again.";
                pnl_Message.Visible = true;
                pnl_Message.CssClass = "loginError";
            }
            else
            {
                // Show Table
                // ----------
                pnl_results.Visible = true;
                ResultsGridView.DataSource = result;
                ResultsGridView.DataBind();

                // Table Header Names
                // ------------------
                ResultsGridView.HeaderRow.Cells[0].Text = "Select";
            }
        }
    }
}
catch (SystemException ex)
{
    var exceptionUtility = new genericExceptions();
    exceptionUtility.genericSystemException(
        ex,
        Server.MachineName,
        Page.TemplateSourceDirectory.Remove(0, 1) + Page.AppRelativeVirtualPath.Remove(0, 1),
        ConfigurationManager.AppSettings["emailSupport"],
        ConfigurationManager.AppSettings["emailFrom"],
        string.Empty);
}
}

我的PageIndexChanging活动我通常会调用,loadGrid()但我没有那种情况。我试过只是添加ResultsGridView.DataBind()但得到错误Sequence contains no elements

protected void ResultsGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
  ResultsGridView.PageIndex = e.NewPageIndex;
  ** How Can I bind the Grid**
}
4

1 回答 1

2

尝试这个..

session["somename"]=result;

protected void ResultsGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
 {
   var somename=session["somename"].Tostring();  
  ResultsGridView.PageIndex = e.NewPageIndex;
  ResultsGridview.Datasource=somename;
  REsultsGridview.Databind();

 }
于 2013-03-11T12:35:34.837 回答