public void BindData() { string author = txtName.Text.Trim(); string phone = txtPhone.Text.Trim(); string email = txtEmail.Text.Trim(); string adr = txtAdress.Text.Trim(); int read = Convert.ToInt32(dropStatus.SelectedValue); string time1 = txtTimer1.Value; string time2 = txtTimer2.Value; try { DataTable dt = MsgBll.getMsg(author, phone, email, adr, time1, time2, read); if (dt.Rows.Count > 0) { AspNetPager1.RecordCount = dt.Rows.Count; PagedDataSource pds = new PagedDataSource(); pds.DataSource = dt.DefaultView; pds.PageSize = AspNetPager1.PageSize; pds.AllowPaging = true; pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1; dgMsg.DataSource = pds; dgMsg.DataBind(); } else { dgMsg.DataSource = dt; dgMsg.DataBind(); } } catch (Exception) { DataTable dt = MsgBll.getAllMsg(); if (dt.Rows.Count > 0) { AspNetPager1.RecordCount = dt.Rows.Count; PagedDataSource pds = new PagedDataSource(); pds.DataSource = dt.DefaultView; pds.PageSize = AspNetPager1.PageSize; pds.AllowPaging = true; pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1; dgMsg.DataSource = pds; dgMsg.DataBind(); } else { dgMsg.DataSource = dt; dgMsg.DataBind(); } /*throw;*/ } }
protected void btnShowAllMsg_Click(object sender, EventArgs e) { DataTable dt = MsgBll.getAllMsg(); if (dt.Rows.Count > 0) { AspNetPager1.RecordCount = dt.Rows.Count; PagedDataSource pds = new PagedDataSource(); pds.DataSource = dt.DefaultView; pds.PageSize = AspNetPager1.PageSize; pds.AllowPaging = true; pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1; dgMsg.DataSource = pds; dgMsg.DataBind(); } else { dgMsg.DataSource = null; dgMsg.DataBind(); } }