public static void DropDownListDataBind(string tableName, string fieldName, ListControl drop, int dataValueField) { ChoicesetValueInfo item = new ChoicesetValueInfo(); item.DataTextField = "请选择"; item.DataValueField = -1; item.IsDefault = false; ChoicesetValueInfoCollection dictionaryFieldValueByName = GetDictionaryFieldValueByName(tableName, fieldName); dictionaryFieldValueByName.Insert(0, item); drop.DataSource = dictionaryFieldValueByName; drop.DataTextField = "DataTextField"; drop.DataValueField = "DataValueField"; drop.DataBind(); if (dataValueField != -1) { drop.SelectedValue = dataValueField.ToString(CultureInfo.CurrentCulture); } else { foreach (ChoicesetValueInfo info2 in dictionaryFieldValueByName) { if (info2.IsDefault) { drop.SelectedValue = info2.DataValueField.ToString(CultureInfo.CurrentCulture); break; } } } }
public static ChoicesetValueInfoCollection GetDictionaryFieldValue(ChoicesetInfo choicesetInfo, bool isShowEnable) { ChoicesetValueInfoCollection infos = new ChoicesetValueInfoCollection(); if (!string.IsNullOrEmpty(choicesetInfo.FieldValue)) { string[] strArray = choicesetInfo.FieldValue.Split(new char[] { '$' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < strArray.Length; i++) { string[] strArray2 = strArray[i].Split(new char[] { '|' }); if (strArray2.Length == 3) { ChoicesetValueInfo item = new ChoicesetValueInfo(); item.DataTextField = strArray2[0]; item.IsEnable = DataConverter.CBoolean(strArray2[1]); item.IsDefault = DataConverter.CBoolean(strArray2[2]); item.DataValueField = i; if (isShowEnable) { if (item.IsEnable) { infos.Add(item); } } else { infos.Add(item); } } } } return(infos); }
private void DropDownListDataBind(string fieldName, DropDownList dropClient) { ChoicesetValueInfo item = new ChoicesetValueInfo(); item.DataTextField = ""; item.DataValueField = -1; item.IsDefault = false; ChoicesetValueInfoCollection dictionaryFieldValueByName = Choiceset.GetDictionaryFieldValueByName("PE_Client", fieldName); dictionaryFieldValueByName.Insert(0, item); dropClient.DataSource = dictionaryFieldValueByName; dropClient.DataTextField = "DataTextField"; dropClient.DataValueField = "DataValueField"; dropClient.DataBind(); foreach (ChoicesetValueInfo info2 in dictionaryFieldValueByName) { if (info2.IsDefault) { dropClient.SelectedValue = info2.DataValueField.ToString(); break; } } }
private void CreateFormFieldValueTable() { Table child = new Table(); child.Width = Unit.Parse("100%"); child.Attributes.Add("class", "border"); TableRow row = new TableRow(); row.Attributes.Add("class", "title"); row.Attributes.Add("align", "center"); row.Attributes.Add("height", "25"); TableCell cell = new TableCell(); cell.Text = "序号"; row.Cells.Add(cell); TableCell cell2 = new TableCell(); cell2.Text = "默认"; row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = "启用"; row.Cells.Add(cell3); TableCell cell4 = new TableCell(); cell4.Text = "选项值"; row.Cells.Add(cell4); child.Rows.Add(row); ChoicesetValueInfoCollection dictionaryFieldValue = Choiceset.GetDictionaryFieldValue(this.choicesetInfo); for (int i = 0; i < (dictionaryFieldValue.Count + 3); i++) { ChoicesetValueInfo info; if (i < dictionaryFieldValue.Count) { info = dictionaryFieldValue[i]; } else { info = new ChoicesetValueInfo(); info.IsDefault = false; info.IsEnable = false; info.DataTextField = string.Empty; } TableRow row2 = new TableRow(); row2.Attributes.Add("class", "tdbg"); row2.Attributes.Add("align", "center"); TableCell cell5 = new TableCell(); cell5.Text = i.ToString(); row2.Cells.Add(cell5); TableCell cell6 = new TableCell(); StringBuilder builder = new StringBuilder(); builder.Append(""); builder.Append("<Input type='radio' name='rad' "); builder.Append("id='rad"); builder.Append(i.ToString()); builder.Append("' value="); builder.Append(i.ToString()); if (info.IsDefault) { builder.Append(" checked"); } builder.Append(">"); cell6.Text = builder.ToString(); row2.Cells.Add(cell6); TableCell cell7 = new TableCell(); CheckBox box = new CheckBox(); box.ID = "chk" + ((i + 1)).ToString(); box.EnableViewState = false; box.Checked = info.IsEnable; cell7.Controls.Add(box); row2.Cells.Add(cell7); TableCell cell8 = new TableCell(); cell8.Attributes.Add("align", "left"); TextBox box2 = new TextBox(); box2.ApplyStyleSheetSkin(this); box2.Text = info.DataTextField; box2.ID = "txt" + ((i + 1)).ToString(); box2.EnableViewState = false; cell8.Controls.Add(box2); row2.Cells.Add(cell8); child.Rows.Add(row2); } child.CellPadding = 0; child.CellSpacing = 1; this.PlhFormFieldValue.Controls.Add(child); }