locked
Two gridviews, one with the primary table, one with the secondary table with pagination on the main table RRS feed

  • Question

  • User-1212847090 posted

    OK I have two sql statements to pull data from a primary table and a related table, on the main query I am using pagination to show only one page at a time, the primary key is called ship_order_id the foreign key is called ship_id, I am stuck on filtering the second sql statement, can I pass the value from the gridview into the statement and how would I do that or can I pass the value into the url through the pagination control?

    Here's the two statements in my code behind

    public void GetShipOrderDetails()
    {

    string query = "SELECT *, DateDiff('d', billdate, deldate) AS billdate_deldate_diff FROM qTableShipOrders Where chkloaded=no AND DiscountChecked = no AND Delete=no";

    dt = DataAccess.SelectDataTable_TMS(query);
    GridView1.DataSource = dt;
    GridView1.DataBind();

    _pageIndex = GridView1.PageIndex;
    _totalPages = dt.Rows.Count;
    hfTotal.Value = _totalPages.ToString();
    int current = 0;
    DataTable dtPager;

    dtPager = new DataTable();
    dtPager.Columns.Add("ship_order_ID");
    dtPager.Columns.Add("Text");

    dtPager.Columns.Add("TotalViewing");
    dtPager.Columns.Add("Current");
    dtPager.Columns.Add("CurrentClass");

    dtPager.Columns.Add("IsFirstPrevious");
    dtPager.Columns.Add("IsNextLast");

    for (int i = 0; i <= dt.Rows.Count - 1; i++)
    {
    if (i == 0)
    current = 1;
    else
    current = current + 1;

    dtPager.Rows.Add(dtPager.NewRow());
    dtPager.Rows[i]["ship_order_ID"] = dt.Rows[i]["ship_order_ID"].ToString();
    dtPager.Rows[i]["Text"] = current.ToString();

    dtPager.Rows[i]["TotalViewing"] = "ยอดรวมรายการ: " + _totalPages.ToString() + "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;" + "หน้าที่ <b>" + (_pageIndex + 1) + "</b> ของ <b>" + _totalPages.ToString() + "</b>";

    dtPager.Rows[i]["Current"] = _pageIndex;
    dtPager.Rows[i]["CurrentClass"] = i != _pageIndex;

    dtPager.Rows[i]["IsFirstPrevious"] = _pageIndex == 0 ? false : true;
    dtPager.Rows[i]["IsNextLast"] = (_pageIndex + 1) >= int.Parse(hfTotal.Value) ? false : true;
    }

    rptPager.DataSource = dtPager;
    rptPager.DataBind();
    }

    public void GetConsignmentDetails()
    {
    string WhereClause = " Where 1=1 AND chkloaded=no AND DiscountChecked = no AND Delete=no" ;
    if (Request.QueryString.Count > 0)
    {
    if (Request.QueryString["id"] != null)
    WhereClause += " And ship_id = " + Request.QueryString["id"] + " ";

    }

    string query = "SELECT *, DateDiff('d', billdate, deldate) AS billdate_deldate_diff FROM qTableShipOrdersproducts " + WhereClause;

    dt = DataAccess.SelectDataTable_TMS(query);
    GridView2.DataSource = dt;
    GridView2.DataBind();
    }

    Thanks in advance


    Ben

    Tuesday, March 26, 2019 6:56 AM

All replies