![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 <div class="s"> 2 <input id="txt_name" runat="server" type="text" value="家长姓名" οnfοcus="if(this.value=='家长姓名'){this.value='';this.style.color='red';}" 3 οnblur="if(this.value==''){this.value='家长姓名';this.style.color='grey'};" 4 style="color: gray;padding-top: 0px; height: 18px; width: 96px;"/> 5 <input id="txt_phone" runat="server" type="text" value="家长手机号码" οnfοcus="if(this.value=='家长手机号码'){this.value='';this.style.color='red';}" 6 οnblur="if(this.value==''){this.value='家长手机号码'; this.style.color='grey';}" 7 style=" color:Gray; padding-top:0px; height:18px; width" /> 8 用户状态:<asp:DropDownList ID="DropDownList3" runat="server"> 9 <asp:ListItem Value="0">---请选择用户状态---</asp:ListItem> 10 <asp:ListItem Value="1">正式用户</asp:ListItem> 11 <asp:ListItem Value="2">试用用户</asp:ListItem> 12 </asp:DropDownList> 13 注册时间:<%--<asp:DropDownList ID="DropDownList4" runat="server"> 14 </asp:DropDownList>--%> 15 <input id="retrunPaln" type="text" class="Wdate" runat="server" οnfοcus="WdatePicker()" style="height:18px; padding:0;" /> 16 <asp:Button ID="Button2" runat="server" Text="家长信息查找" OnClick="Button2_Click" /> 17 </div> 18 <br /> 19 <div class="s"> 20 <asp:HiddenField ID="HiddenField3" runat="server" Value="stus" /> 21 <input id="txt_stuname" type="text" runat="server" value="学生姓名" οnfοcus="if(this.value=='学生姓名'){this.value='';this.style.color='red';}" 22 οnblur="if(this.value==''){this.value='学生姓名';this.style.color='gray';}" 23 style=" color:Gray; padding-top:0px; height:18px; width:96px;" /> 24 <input id="txt_stustudynum" type="text" runat="server" value="学生学号" οnfοcus="if(this.value=='学生学号'){this.value='';this.style.color='red';}" 25 οnblur="if(this.value==''){this.value='学生学号';this.style.color='gray';}" 26 style=" color:Gray; padding-top:0px; height:18px; width:96px;" /> 27 <asp:Button ID="Button1" runat="server" Text="学生信息查找" OnClick="Button1_Click" /> 28 </div>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
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 }