1 protected void Page_Load(object sender, EventArgs e)
2 {
3 if (!IsPostBack)
4 {
5 ParentListBindData(true, false);
6 StudentListBindData(true, false);
7 }
8 }
9 /// <summary>
10 /// 绑定家长信息数据
11 /// </summary>
12 /// <param name="getCondition">是否绑定筛选条件(只第一次加载)</param>
13 /// <param name="toOnePage">是否回到第一页(当点击查找按钮时)</param>
14 private void ParentListBindData(bool getCondition, bool toOnePage)
15 {
16 if (getCondition)
17 {
18 DataTable pdt = parentbll.GetParentList(string.Empty).Tables[0];
19 DataRow pdr = pdt.NewRow();
20 pdr["pk_parents"] = new Guid();
21 pdt.Rows.InsertAt(pdr, 0);
22 ViewState["pageIndex"] = 1;
23 ViewState["pageSize"] = 15;
24 }
25 int pageIndex = Convert.ToInt32(ViewState["pageIndex"]);
26 int pageSize = Convert.ToInt32(ViewState["pageSize"]);
27 StringBuilder strwhere = new StringBuilder();
28
29 if (txt_name.Value != "家长姓名" && txt_name.Value.Trim() != string.Empty) strwhere.Append(string.Format(" and name like '%{0}%'", txt_name.Value));
30 if (txt_phone.Value != "家长手机号码" && txt_phone.Value.Trim() != string.Empty) strwhere.Append(string.Format(" and phone like '%{0}%'", txt_phone.Value));
31 if (this.DropDownList3.SelectedIndex != 0) strwhere.Append(string.Format(" and Utype='{0}'", DropDownList3.SelectedValue));
32 if (retrunPaln.Value != string.Empty) strwhere.Append(string.Format(" and CreateOn like '%{0}%'", retrunPaln.Value));
33 LvParentList.DataSource = parentbll.GetParentList(strwhere.ToString(), (pageIndex - 1) * pageSize + 1, pageIndex * pageSize, false).Tables[0];
34 LvParentList.DataBind();
35 }
36 //家长查找
37 protected void Button2_Click(object sender, EventArgs e)
38 {
39 ParentListBindData(false, true);
40 }
41 //分页
42 protected void LvParentList_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
43 {
44 DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
45 ParentListBindData(false, true);
46 StudentListBindData(false, true);
47 }
48 //显示当前页和总页数
49 protected void LvParentList_DataBound(object sender, EventArgs e)
50 {
51 lblPageIndex.Text = (DataPager1.StartRowIndex / DataPager1.MaximumRows + 1).ToString();
52 string fenye = Math.Ceiling(Convert.ToDouble(DataPager1.TotalRowCount / DataPager1.PageSize)).ToString();
53 if (fenye == "0")
54 {
55 lblPageCount.Text = "1";
56 }
57 else
58 {
59 lblPageCount.Text = Math.Ceiling(Convert.ToDouble(DataPager1.TotalRowCount / DataPager1.PageSize)).ToString();
60 }
61 }
62 //在ListView的ItemDataBound事件里找出Repeater并绑定值。
63 protected void LvParentList_ItemDataBound(object sender, ListViewItemEventArgs e)
64 {
65 if (e.Item.ItemType == ListViewItemType.DataItem)
66 {
67 //隐藏域的值
68 HiddenField hf = (HiddenField)e.Item.FindControl("HiddenField1");
69 ((Repeater)e.Item.FindControl("Repeater1")).DataSource = new Bll.BllBasicStudent().GetModelDtailByParentId(hf.Value);
70 ((Repeater)e.Item.FindControl("Repeater1")).DataBind();
71 }
72 }