private void BindData() { BLL.UserLoanRep UserLoanRepManager = new BLL.UserLoanRep(); string strWhere = ""; if (0 == nUserID) { strWhere = "ISNULL(UserId, 0)=0"; } else { strWhere = string.Format("(ISNULL(UserId, 0)=0 OR UserId={0})", nUserID); } if (!string.IsNullOrEmpty(lastNamefilter.Trim())) { strWhere += string.Format(" And Name LIKE '%{0}%' ", lastNamefilter.Trim()); } strWhere += " Order by Name "; DataSet dsLoanRep = UserLoanRepManager.GetList(strWhere); this.gridLoanRep.DataSource = dsLoanRep; this.gridLoanRep.DataBind(); }
protected void lbtnAdd_Click(object sender, EventArgs e) { // return selected record as XML XmlDocument xmlDoc = new XmlDocument(); XmlElement element = xmlDoc.CreateElement("root"); xmlDoc.AppendChild(element); XmlElement childElement = null; XmlAttribute attri = null; foreach (GridViewRow row in gridLoanRep.Rows) { CheckBox ckbSelected = row.FindControl("ckbSelected") as CheckBox; if (ckbSelected.Checked) { var id = gridLoanRep.DataKeys[row.RowIndex].Value.ToString(); if (!listCurrRow.Contains(id)) //曾经选过 就不添加 { childElement = xmlDoc.CreateElement("LoanRep"); element.AppendChild(childElement); attri = xmlDoc.CreateAttribute("NameId"); attri.Value = id; childElement.Attributes.Append(attri); attri = xmlDoc.CreateAttribute("Name"); attri.Value = gridLoanRep.DataKeys[row.RowIndex][1].ToString(); childElement.Attributes.Append(attri); } } } ///补充 原有选过的 /// if (strCurrRecord.Count() > 0) { BLL.UserLoanRep UserLoanRepManager = new BLL.UserLoanRep(); string strWhere = ""; if (0 == nUserID) { strWhere = "ISNULL(UserId, 0)=0"; } else { strWhere = string.Format("(ISNULL(UserId, 0)=0 OR UserId={0})", nUserID); } strWhere += string.Format(" And NameId in({0}) ", strCurrRecord); DataSet dsLoanRep = UserLoanRepManager.GetList(strWhere); if (dsLoanRep != null && dsLoanRep.Tables[0].Rows.Count > 0) { foreach (DataRow dr in dsLoanRep.Tables[0].Rows) { childElement = xmlDoc.CreateElement("LoanRep"); element.AppendChild(childElement); attri = xmlDoc.CreateAttribute("NameId"); attri.Value = dr["NameId"].ToString(); childElement.Attributes.Append(attri); attri = xmlDoc.CreateAttribute("Name"); attri.Value = dr["Name"].ToString(); childElement.Attributes.Append(attri); } } } ClientFun("callback", string.Format("callBack('{0}');", xmlDoc.OuterXml.Replace('<', '\u0001'))); }