private void BindContactBranch() { try { ddlBranch.Items.Clear(); ContactBranches branch = new ContactBranches(); string strWhere = " Enabled=1 "; if (ddlCompany.SelectedValue != "0") { strWhere += string.Format(" AND ContactCompanyID={0} ", ddlCompany.SelectedValue.Trim()); } DataSet ds = branch.GetList(0, strWhere, " [Name] asc"); if (ds == null) { return; } ddlBranch.DataValueField = "ContactBranchID"; ddlBranch.DataTextField = "Name"; ddlBranch.Items.Add(new ListItem("--select--", "0")); ddlBranch.SelectedIndex = 0; foreach (DataRow dr in ds.Tables[0].Rows) { ddlBranch.Items.Add(new ListItem(dr["Name"].ToString(), dr["ContactBranchID"].ToString())); } } catch { } }
protected void Page_Load(object sender, EventArgs e) { // json示例 // {"ContactBranchId":{0},"Name":"{1}","Address":"{2}","City":"{3}","State":"{4}","Zip":"{5}"} #region 接收参数 string respTempl = "^0^\"ContactBranchId\":{0},\"Name\":\"{1}\",\"Address\":\"{2}\",\"City\":\"{3}\",\"State\":\"{4}\",\"Zip\":\"{5}\"^1^"; // DelContactID bool bIsValid = PageCommon.ValidateQueryString(this, "ContactBranchId", QueryStringType.ID); if (bIsValid == false) { this.Response.Write(string.Format("{\"ContactBranchId\":{0},\"Name\":\"{1}\",\"Address\":\"{2}\",\"City\":\"{3}\",\"State\":\"{4}\",\"Zip\":\"{5}\"}", 0)); return; } string sContactBranchId = this.Request.QueryString["ContactBranchId"].ToString(); int iContactBranchId = Convert.ToInt32(sContactBranchId); #endregion #region Branch ContactBranches contactBranch = new ContactBranches(); try { DataSet dsCBranch = contactBranch.GetList(" ContactBranchId = " + iContactBranchId.ToString()); if (dsCBranch != null && dsCBranch.Tables.Count > 0 && dsCBranch.Tables[0].Rows.Count > 0) { DataRow dr = dsCBranch.Tables[0].Rows[0]; string rspStr = string.Format(respTempl , dr["ContactBranchId"] != DBNull.Value ? dr["ContactBranchId"].ToString() : "0" , dr["Name"] != DBNull.Value ? dr["Name"].ToString() : "" , dr["Address"] != DBNull.Value ? dr["Address"].ToString() : "" , dr["City"] != DBNull.Value ? dr["City"].ToString() : "" , dr["State"] != DBNull.Value ? dr["State"].ToString() : "" , dr["Zip"] != DBNull.Value ? dr["Zip"].ToString() : "" ); this.Response.Write(respStrReplace(rspStr)); return; } this.Response.Write(string.Format(respTempl, 0)); return; } catch { this.Response.Write(string.Format(respTempl, 0)); return; } #endregion }
/// <summary> /// Bind Page default values /// </summary> private void BindPageDefaultValues() { try { //Bind Alphabet foreach (string alphabet in alphabets.Split(',')) { ddlAlphabets.Items.Add(new ListItem(alphabet, alphabet)); } //Bind State LPWeb.Layouts.LPWeb.Common.USStates.Init(this.ddlStates); //Bind Branch ContactBranches contactBranch = new ContactBranches(); DataSet dsCBranch = contactBranch.GetList(" Enabled='true' Order by Name asc"); DataRow drNew = dsCBranch.Tables[0].NewRow(); drNew["ContactBranchId"] = 0; drNew["Name"] = "-- Select Branch --"; dsCBranch.Tables[0].Rows.InsertAt(drNew, 0); this.ddlBranch.DataSource = dsCBranch.Tables[0]; this.ddlBranch.DataValueField = "ContactBranchId"; this.ddlBranch.DataTextField = "Name"; this.ddlBranch.DataBind(); //this.ddlBranch.SelectedValue = CurrUser. // autocomplete address this.ddlBranchAddress.DataSource = dsCBranch.Tables[0]; this.ddlBranchAddress.DataBind(); List <string> s = new List <string>(); if (this.ContactId == 0) { this.btnDelete.Disabled = true; } else { this.btnDelete.Disabled = false; } } catch (Exception ex) { throw ex; } }
private void BindBranches() { try { LPWeb.BLL.ContactBranches bllBranch = new ContactBranches(); ddlBranchs.DataSource = bllBranch.GetList(" Enabled=1 order by Name"); ddlBranchs.DataBind(); var item = new ListItem("All Branches", "0") { Selected = true }; ddlBranchs.Items.Insert(0, item); } catch { } }