Example #1
0
        private void getContent(int id)
        {
            int currentPage = Request["page"] == null ? 1 : int.Parse(Request["page"]);

            string        connectstring = WebConfigurationManager.ConnectionStrings["tayanaConnectionString"].ToString();
            SqlConnection connect       = new SqlConnection(connectstring);


            string sqlsearch = " where countryID = @countryID";
            string sqlstring = $@"with newsList as
                (SELECT  row_number() over(order by country.id asc) as rownumber, area.countryID, country.country, area.area, dealer.areaID, dealer.photo, dealer.dealer, dealer.id as dealerID
            FROM      area INNER JOIN
            country ON area.countryID = country.id INNER JOIN
            dealer ON area.id = dealer.areaID{sqlsearch})
            select* from newsList";
            string sqlpage   = " where rownumber >= @start and rownumber <= @end";

            SqlCommand getsql = new SqlCommand(sqlstring + sqlpage, connect);

            getsql.Parameters.AddWithValue("@countryID", id);

            getsql.Parameters.Add("@start", SqlDbType.Int);
            getsql.Parameters["@start"].Value = ((currentPage - 1) * PageSize) + 1;
            getsql.Parameters.Add("@end", SqlDbType.Int);
            getsql.Parameters["@end"].Value = currentPage * PageSize;

            SqlDataAdapter adapter = new SqlDataAdapter(getsql);
            DataTable      table   = new DataTable();

            adapter.Fill(table);
            Dealers.DataSource = table;
            Dealers.DataBind();

            //產分頁
            string page      = @"area INNER JOIN
            country ON area.countryID = country.id INNER JOIN
            dealer ON area.id = dealer.areaID";
            string pagecount = " where country.id=@id ";

            SqlCommand totalcommand = new SqlCommand($@"select count(*) from {page} " + pagecount, connect);

            totalcommand.Parameters.AddWithValue("@id", id);
            SqlDataAdapter totalAdapter = new SqlDataAdapter(totalcommand);
            DataTable      totalTable   = new DataTable();

            totalAdapter.Fill((totalTable));
            int total = Convert.ToInt32(totalTable.Rows[0][0]);

            Pagination.totalitems = total;
            Pagination.limit      = PageSize;
            Pagination.targetpage = "dealers.aspx";
            Pagination.showPageControls();
        }