本文整理汇总了C#中System.Web.UI.WebControls.ListControl类的典型用法代码示例。如果您正苦于以下问题:C# ListControl类的具体用法?C# ListControl怎么用?C# ListControl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ListControl类属于System.Web.UI.WebControls命名空间,在下文中一共展示了ListControl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Fillchk
public static void Fillchk(ListControl control, string key, string value, object data)
{
control.DataSource = data;
control.DataValueField = key;
control.DataTextField = value;
control.DataBind();
}
示例2: McssWebQuestion
public McssWebQuestion(string strId, bool bRequired, string strRequiredText, string strQuestion, string strControlBase, RepeatDirection rdLayout, string[] strResponses)
: base(strId, "mcss", bRequired, strRequiredText, strQuestion)
{
this.m_radioButtonList = new RadioButtonList();
this.m_dropDownList = new DropDownList();
this.m_listControl = null;
if (strControlBase == "dropdown")
{
this.m_listControl = this.m_dropDownList;
}
else
{
this.m_radioButtonList.RepeatDirection = rdLayout;
this.m_listControl = this.m_radioButtonList;
}
foreach (string text in strResponses)
{
this.m_listControl.Items.Add(new ListItem(text));
}
this.m_listControl.ID = "lst_" + strId;
if (bRequired)
{
ListControlValidator child = new ListControlValidator();
child.EnableClientScript = false;
child.Text = strRequiredText;
child.Display = ValidatorDisplay.Dynamic;
child.ControlToValidate = this.m_listControl.ID;
this.Controls.Add(child);
}
this.Controls.Add(this.m_listControl);
this.Controls.Add(new LiteralControl("</p>"));
}
示例3: PopulateListControl2
public new void PopulateListControl2(ListControl listControl)
{
var filterAttribute = Column.GetAttribute<FilterForeignKeyAttribute>();
if (filterAttribute == null || Session[filterAttribute.SessionVariableName] == null)
{
base.PopulateListControl(listControl);
return;
}
var context = Column.Table.CreateContext();
var foreignKeyTable = ForeignKeyColumn.ParentTable;
var filterColumn = foreignKeyTable.GetColumn(filterAttribute.FilterColumnName);
var value = Convert.ChangeType(Session[filterAttribute.SessionVariableName].ToString(), filterColumn.TypeCode, CultureInfo.InvariantCulture);
var query = foreignKeyTable.GetQuery(context); // Get Column Value query
var entityParam = Expression.Parameter(foreignKeyTable.EntityType, foreignKeyTable.Name); // get the table entity to be filtered
var property = Expression.Property(entityParam, filterColumn.Name); // get the property to be filtered
var equalsCall = Expression.Equal(property, Expression.Constant(value)); // get the equal call
var whereLambda = Expression.Lambda(equalsCall, entityParam); // get the where lambda
var whereCall = Expression.Call(typeof(Queryable), "Where", new Type[] { foreignKeyTable.EntityType }, query.Expression, whereLambda); // get the where call
var values = query.Provider.CreateQuery(whereCall);
foreach (var row in values)
{
listControl.Items.Add(new ListItem()
{
Text = foreignKeyTable.GetDisplayString(row),
Value = foreignKeyTable.GetPrimaryKeyString(row)
});
}
}
示例4: ListPropertyBinding
/// <summary>
/// Constructs a new list property binding for the given ListControl element.
/// </summary>
/// <param name="list">The list control to be bound to the data property.</param>
protected ListPropertyBinding(ListControl list)
: base(list)
{
bool isMultiVal = control is ListBox || control is CheckBoxList;
// ListBox and CheckBoxList post values on selection change, since deselecting all has no post value
// and we have to use selection change to detect this as opposed to no post at all
if (isMultiVal)
{
PostedValue = null;
list.SelectedIndexChanged += delegate
{
if (isMultiVal && property != null && control.Page != null)
{
PostedValue = control.Page.Request.Form[control.UniqueID] ?? "";
// for CheckBoxList each item is posted individually, so we just reconstruct it
// from the selected item, since LoadPostData should have happened by now.
if (control is CheckBoxList)
{
List<string> newValues = new List<string>();
foreach (ListItem item in list.Items)
if (item.Selected && !newValues.Contains(item.Value)) newValues.Add(item.Value);
PostedValue = string.Join(",", newValues.ToArray());
}
UpdateProperty(PostedValue);
}
};
}
}
示例5: FillRange
public static void FillRange(ListControl control, int min = 1, int max = 10)
{
control.DataSource = GetRange(min, max);
control.DataValueField = "key";
control.DataTextField = "value";
control.DataBind();
}
示例6: PopulateListControl
/// <summary>
/// Populate a ListControl with all the items in the foreign table
/// </summary>
/// <param name="listControl"></param>
/// <param name="dataSource"></param>
/// <parm name="valueField"></parm>
/// <parm name="defaultTextField"></parm>
protected void PopulateListControl(ListControl listControl, IQueryable dataSource, string valueField)
{
var filterdata = new List<KeyValuePair<string, string>>();
string textField = string.Empty;
if (dataSource != null)
{
if (_filterFields.ForeignText != string.Empty)
{
if (CheckDropDownTextField(_filterFields.ForeignText, dataSource.ElementType)) {
textField = _filterFields.ForeignText;
}
}
if (textField == string.Empty) {
textField = FindDropDownTextField(Column.FieldName, dataSource.ElementType);
}
foreach (object dataItem in dataSource) {
filterdata.Add(new KeyValuePair<string, string>(DataBinder.GetPropertyValue(dataItem, textField, null), DataBinder.GetPropertyValue(dataItem, valueField, null)));
}
if (_filterFields.SortField == "Yes")
{
if (_filterFields.SortDescending)
filterdata.Sort(CompareDesc);
else
filterdata.Sort(CompareAsc);
}
foreach (KeyValuePair<string, string> keyvalue in filterdata) {
listControl.Items.Add(new ListItem(keyvalue.Key, _filterFields.FieldName + ":" + keyvalue.Value));
}
}
}
示例7: Flip
public static void Flip(Label lbl, ListControl lst, bool blnReadOnly)
{
lbl.Visible = blnReadOnly;
lst.Visible = !blnReadOnly;
if (blnReadOnly)
{
lbl.Text = "";
foreach (ListItem item in lst.Items)
{
if (item.Selected)
{
lbl.Text = lbl.Text + "<br>" + item.Text;
}
}
if (lbl.Text != "")
{
lbl.Text = lbl.Text.Remove(0, 4);
}
}
else
{
string str = lbl.Text.Replace("<br>", ",");
if (str != "")
{
foreach (string str2 in str.Split(new char[] { ',' }))
{
SelectedByText(lst, str2);
}
}
}
}
示例8: GetSelectedInt
public static int? GetSelectedInt(ListControl ddl) {
int? iVal = null;
if (ddl.SelectedItem != null) {
iVal = int.Parse(ddl.SelectedValue);
}
return iVal;
}
示例9: Bind2Ddl
public static void Bind2Ddl(ListControl ddl, DataTable dt, string textField, string valueField)
{
ddl.DataSource = dt;
ddl.DataTextField = textField;
ddl.DataValueField = valueField;
ddl.DataBind();
}
示例10: BindList
public static void BindList(ListControl _ltControl, bool _bIncludeSel, bool _bIncludeAll, bool _bIncludeTip)
{
if (null != _ltControl)
{
_ltControl.Items.Clear();
if (_bIncludeAll)
{
_ltControl.Items.Add(new ListItem("--全部--", ""));
}
if (_bIncludeSel)
{
_ltControl.Items.Add(new ListItem("--请选择--", ""));
}
SystemRole[] alist = SystemRole.List();
if (alist != null && alist.Length != 0)
{
SystemRole[] array = alist;
for (int i = 0; i < array.Length; i++)
{
SystemRole item = array[i];
ListItem li = new ListItem(item.Name, string.Concat(item.Id));
if (_bIncludeTip)
{
li.Attributes["title"] = item.Description;
}
_ltControl.Items.Add(li);
}
}
}
}
示例11: GetSelectedGuid
public static Guid? GetSelectedGuid(ListControl ddl) {
Guid? gVal = null;
if (ddl.SelectedItem != null) {
gVal = new Guid(ddl.SelectedValue);
}
return gVal;
}
示例12: GetValue
protected override object GetValue(ListControl ddl)
{
if (!string.IsNullOrEmpty(ddl.SelectedValue))
return GetEnumValue(int.Parse(ddl.SelectedValue));
else
return null;
}
示例13: BindList
public static void BindList(ListControl _ltControl, bool _bIncludeSel, bool _bIncludeAll)
{
if (null != _ltControl)
{
_ltControl.Items.Clear();
if (_bIncludeAll)
{
_ltControl.Items.Add(new ListItem("--全部--", ""));
}
if (_bIncludeSel)
{
_ltControl.Items.Add(new ListItem("--请选择--", ""));
}
SystemOrganization[] alist = SystemOrganization.List();
if (alist != null && alist.Length != 0)
{
SystemOrganization[] array = alist;
for (int i = 0; i < array.Length; i++)
{
SystemOrganization item = array[i];
ListItem li = new ListItem(item.Name, string.Concat(item.Id));
_ltControl.Items.Add(li);
}
}
}
}
示例14: AddListItems
public static void AddListItems(ListControl control, string keys, string values, string selectedValues)
{
if (control == null)
{
return;
}
if (string.IsNullOrWhiteSpace(keys))
{
return;
}
if (string.IsNullOrWhiteSpace(values))
{
return;
}
var key = keys.Split(',');
var value = values.Split(',');
if (key.Count() != value.Count())
{
throw new InvalidOperationException("Key or value count mismatch. Cannot add items to " + control.ID);
}
for (var i = 0; i < key.Length; i++)
{
var item = new ListItem(key[i].Trim(), value[i].Trim());
control.Items.Add(item);
}
foreach (ListItem item in control.Items)
{
//Checkbox list allows multiple selection.
if (control is CheckBoxList)
{
if (!string.IsNullOrWhiteSpace(selectedValues))
{
foreach (var selectedValue in selectedValues.Split(','))
{
if (item.Value.Trim().Equals(selectedValue.Trim()))
{
item.Selected = true;
}
}
}
}
else
{
if (!string.IsNullOrWhiteSpace(selectedValues))
{
if (item.Value.Trim().Equals(selectedValues.Split(',').Last().Trim()))
{
item.Selected = true;
break;
}
}
}
}
}
示例15: Bind2RadioButtonList
// This function binds the given RadioButtonList with the given data table with respect to the data text field and the value field.
public static void Bind2RadioButtonList(ListControl rbl, DataTable dt, string textField, string valueField)
{
rbl.DataSource = dt;
rbl.DataTextField = textField;
rbl.DataValueField = valueField;
rbl.DataBind();
}