本文整理汇总了C#中System.Web.UI.WebControls.DropDownList.AddCssClass方法的典型用法代码示例。如果您正苦于以下问题:C# DropDownList.AddCssClass方法的具体用法?C# DropDownList.AddCssClass怎么用?C# DropDownList.AddCssClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.WebControls.DropDownList
的用法示例。
在下文中一共展示了DropDownList.AddCssClass方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderBaseControl
/// <summary>
/// Renders the base control.
/// </summary>
/// <param name="writer">The writer.</param>
public virtual void RenderBaseControl( HtmlTextWriter writer )
{
Dictionary<string, string> definedValues = null;
if ( DefinedTypeId.HasValue )
{
definedValues = new Dictionary<string, string>();
new DefinedValueService( new RockContext() )
.GetByDefinedTypeId( DefinedTypeId.Value )
.ToList()
.ForEach( v => definedValues.Add( v.Id.ToString(), v.Value ) );
}
else if ( CustomValues != null )
{
definedValues = CustomValues;
}
writer.AddAttribute( HtmlTextWriterAttribute.Class, "value-list" );
writer.RenderBeginTag( HtmlTextWriterTag.Span );
writer.WriteLine();
_hfValue.RenderControl( writer );
writer.WriteLine();
StringBuilder valueHtml = new StringBuilder();
valueHtml.Append( @"<div class=""controls controls-row form-control-group"">");
if ( definedValues != null )
{
valueHtml.Append( @"<select class=""form-control input-width-lg js-value-list-input""><option value=""""></option>" );
foreach ( var definedValue in definedValues )
{
valueHtml.AppendFormat( @"<option value=""{0}"">{1}</option>", definedValue.Key, definedValue.Value );
}
valueHtml.Append( @"</select>" );
}
else
{
valueHtml.AppendFormat( @"<input class=""form-control input-width-lg js-value-list-input"" type=""text"" placeholder=""{0}""></input>", ValuePrompt );
}
valueHtml.Append( @"<a href=""#"" class=""btn btn-sm btn-danger value-list-remove""><i class=""fa fa-minus-circle""></i></a></div>" );
var hfValueHtml = new HtmlInputHidden();
hfValueHtml.AddCssClass( "js-value-list-html" );
hfValueHtml.Value = valueHtml.ToString();
hfValueHtml.RenderControl( writer );
writer.AddAttribute( HtmlTextWriterAttribute.Class, "value-list-rows" );
writer.RenderBeginTag( HtmlTextWriterTag.Span );
writer.WriteLine();
string[] values = this.Value.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries );
foreach ( string value in values )
{
writer.AddAttribute( HtmlTextWriterAttribute.Class, "controls controls-row form-control-group" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
writer.WriteLine();
if ( definedValues != null )
{
DropDownList ddl = new DropDownList();
ddl.AddCssClass( "form-control input-width-lg js-value-list-input" );
ddl.DataTextField = "Value";
ddl.DataValueField = "Key";
ddl.DataSource = definedValues;
ddl.DataBind();
ddl.Items.Insert( 0, new ListItem( string.Empty, string.Empty ) );
ddl.SelectedValue = value;
ddl.RenderControl( writer );
}
else
{
writer.AddAttribute( HtmlTextWriterAttribute.Class, "form-control input-width-lg js-value-list-input" );
writer.AddAttribute( HtmlTextWriterAttribute.Type, "text" );
writer.AddAttribute( "placeholder", ValuePrompt );
writer.AddAttribute( HtmlTextWriterAttribute.Value, value );
writer.RenderBeginTag( HtmlTextWriterTag.Input );
writer.RenderEndTag();
}
writer.Write( " " );
writer.WriteLine();
// Write Remove Button
writer.AddAttribute( HtmlTextWriterAttribute.Href, "#" );
writer.AddAttribute( HtmlTextWriterAttribute.Class, "btn btn-sm btn-danger value-list-remove" );
writer.RenderBeginTag( HtmlTextWriterTag.A );
writer.AddAttribute(HtmlTextWriterAttribute.Class, "fa fa-minus-circle");
writer.RenderBeginTag( HtmlTextWriterTag.I );
writer.RenderEndTag();
writer.RenderEndTag();
writer.WriteLine();
writer.RenderEndTag();
writer.WriteLine();
}
//.........这里部分代码省略.........
示例2: RenderEntityFieldsControls
/// <summary>
/// Renders the entity fields controls.
/// </summary>
/// <param name="entityType">Type of the entity.</param>
/// <param name="filterControl">The filter control.</param>
/// <param name="writer">The writer.</param>
/// <param name="entityFields">The entity fields.</param>
/// <param name="groupedControls">The grouped controls.</param>
/// <param name="ddlEntityField">The DDL entity field.</param>
public void RenderEntityFieldsControls( Type entityType, FilterField filterControl, HtmlTextWriter writer, List<EntityField> entityFields, Dictionary<string, List<Control>> groupedControls, DropDownList ddlEntityField )
{
string selectedEntityField = ddlEntityField.SelectedValue;
writer.AddAttribute( "class", "row js-filter-row" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
writer.AddAttribute( "class", "col-md-3" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
ddlEntityField.AddCssClass( "entity-property-selection" );
ddlEntityField.RenderControl( writer );
writer.RenderEndTag();
StringBuilder sb = new StringBuilder();
int i = 0;
writer.AddAttribute( "class", "col-md-9" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
foreach ( var entityField in entityFields )
{
if ( entityField.Name != selectedEntityField )
{
writer.AddStyleAttribute( HtmlTextWriterStyle.Display, "none" );
}
writer.AddAttribute( "class", "row field-criteria" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
var propertyControls = groupedControls[entityField.Name];
if ( propertyControls.Count == 1 )
{
writer.AddAttribute( "class", "col-md-1" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
writer.Write( "<span class='data-view-filter-label'>is</span>" );
writer.RenderEndTag();
writer.AddAttribute( "class", "col-md-11" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
propertyControls[0].RenderControl( writer );
writer.RenderEndTag();
}
else if ( propertyControls.Count == 2 )
{
writer.AddAttribute( "class", "col-md-4" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
propertyControls[0].RenderControl( writer );
writer.RenderEndTag();
writer.AddAttribute( "class", "col-md-8" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
propertyControls[1].RenderControl( writer );
writer.RenderEndTag();
}
writer.RenderEndTag(); // row
string clientFormatSelection = string.Empty;
switch ( entityField.FilterFieldType )
{
case SystemGuid.FieldType.TIME:
case SystemGuid.FieldType.DATE:
clientFormatSelection = string.Format( "result = '{0} ' + $('select', $selectedContent).find(':selected').text() + ( $('input', $selectedContent).filter(':visible').length ? (' \\'' + $('input', $selectedContent).filter(':visible').val() + '\\'') : '' )", entityField.Title );
break;
case SystemGuid.FieldType.DECIMAL:
case SystemGuid.FieldType.INTEGER:
case SystemGuid.FieldType.TEXT:
clientFormatSelection = string.Format( "result = '{0} ' + $('select', $selectedContent).find(':selected').text() + ( $('input', $selectedContent).filter(':visible').length ? (' \\'' + $('input', $selectedContent).filter(':visible').val() + '\\'') : '' )", entityField.Title );
break;
case SystemGuid.FieldType.MULTI_SELECT:
clientFormatSelection = string.Format( "var selectedItems = ''; $('input:checked', $selectedContent).each(function() {{ selectedItems += selectedItems == '' ? '' : ' or '; selectedItems += '\\'' + $(this).parent().text() + '\\'' }}); result = '{0} is ' + selectedItems ", entityField.Title );
break;
case SystemGuid.FieldType.DAY_OF_WEEK:
case SystemGuid.FieldType.SINGLE_SELECT:
clientFormatSelection = string.Format( "result = '{0} is ' + '\\'' + $('select', $selectedContent).find(':selected').text() + '\\''", entityField.Title );
break;
}
if ( clientFormatSelection != string.Empty )
{
string lineFormat = @"
case {0}: {1}; break;";
sb.AppendFormat( lineFormat, i, clientFormatSelection );
}
i++;
}
//.........这里部分代码省略.........
示例3: RenderBaseControl
/// <summary>
/// Renders the base control.
/// </summary>
/// <param name="writer">The writer.</param>
public override void RenderBaseControl( HtmlTextWriter writer )
{
Dictionary<string, string> values = null;
if ( DefinedTypeId.HasValue )
{
values = new Dictionary<string, string>();
new DefinedValueService( new RockContext() )
.GetByDefinedTypeId( DefinedTypeId.Value )
.ToList()
.ForEach( v => values.Add( v.Id.ToString(), v.Value ) );
}
else if ( CustomValues != null )
{
values = CustomValues;
}
writer.AddAttribute( HtmlTextWriterAttribute.Class, "key-value-list " + this.CssClass );
writer.AddAttribute( HtmlTextWriterAttribute.Id, this.ClientID );
writer.RenderBeginTag( HtmlTextWriterTag.Span );
writer.WriteLine();
_hfValue.RenderControl( writer );
writer.WriteLine();
StringBuilder html = new StringBuilder();
html.Append( @"<div class=""controls controls-row form-control-group"">");
if ( CustomKeys != null && CustomKeys.Any() )
{
html.Append( @"<select class=""key-value-key form-control input-width-md js-key-value-input"">" );
foreach ( var key in CustomKeys )
{
html.AppendFormat( @"<option value=""{0}"">{1}</option>", key.Key, key.Value );
}
html.Append( @"</select>" );
}
else
{
html.AppendFormat( @"<input class=""key-value-key form-control input-width-md js-key-value-input"" type=""text"" placeholder=""{0}""></input> ", KeyPrompt );
}
if ( values != null )
{
html.Append( @"<select class=""key-value-value form-control input-width-md js-key-value-input"">" );
foreach ( var value in values )
{
html.AppendFormat( @"<option value=""{0}"">{1}</option>", value.Key, value.Value );
}
html.Append( @"</select>" );
}
else
{
html.AppendFormat( @"<input class=""key-value-value input-width-md form-control js-key-value-input"" type=""text"" placeholder=""{0}""></input>", ValuePrompt );
}
html.Append( @"<a href=""#"" class=""btn btn-sm btn-danger key-value-remove""><i class=""fa fa-minus-circle""></i></a></div>" );
var hfValueHtml = new HtmlInputHidden();
hfValueHtml.AddCssClass( "js-value-html" );
hfValueHtml.Value = html.ToString();
hfValueHtml.RenderControl( writer );
writer.AddAttribute( HtmlTextWriterAttribute.Class, "key-value-rows" );
writer.RenderBeginTag( HtmlTextWriterTag.Span );
writer.WriteLine();
string[] nameValues = this.Value.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries );
foreach ( string nameValue in nameValues )
{
string[] nameAndValue = nameValue.Split( new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries );
writer.AddAttribute( HtmlTextWriterAttribute.Class, "controls controls-row form-control-group" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
writer.WriteLine();
// Write Key
if ( CustomKeys != null && CustomKeys.Any() )
{
DropDownList ddl = new DropDownList();
ddl.AddCssClass( "key-value-key form-control input-width-md js-key-value-input" );
ddl.DataTextField = "Value";
ddl.DataValueField = "Key";
ddl.DataSource = CustomKeys;
ddl.DataBind();
if ( nameAndValue.Length >= 1 )
{
ddl.SelectedValue = nameAndValue[0];
}
ddl.RenderControl( writer );
}
else
{
// Write Name
writer.AddAttribute( HtmlTextWriterAttribute.Class, "key-value-key form-control input-width-md js-key-value-input" );
writer.AddAttribute( HtmlTextWriterAttribute.Type, "text" );
writer.AddAttribute( HtmlTextWriterAttribute.Value, nameAndValue.Length >= 1 ? nameAndValue[0] : string.Empty );
writer.AddAttribute( "placeholder", KeyPrompt );
writer.RenderBeginTag( HtmlTextWriterTag.Input );
//.........这里部分代码省略.........
示例4: RenderControl
/// <summary>
/// Outputs server control content to a provided <see cref="T:System.Web.UI.HtmlTextWriter" /> object and stores tracing information about the control if tracing is enabled.
/// </summary>
/// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter" /> object that receives the control content.</param>
public override void RenderControl( HtmlTextWriter writer )
{
writer.AddAttribute( HtmlTextWriterAttribute.Class, "key-value-list" );
writer.RenderBeginTag( HtmlTextWriterTag.Span );
writer.WriteLine();
base.RenderControl( writer );
writer.WriteBreak();
writer.WriteLine();
writer.AddAttribute( HtmlTextWriterAttribute.Class, "key-value-rows" );
writer.RenderBeginTag( HtmlTextWriterTag.Span );
writer.WriteLine();
List<DefinedValue> values = null;
if ( DefinedTypeId.HasValue )
{
values = new DefinedValueService().GetByDefinedTypeId( DefinedTypeId.Value ).ToList();
}
string[] nameValues = this.Value.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries );
foreach ( string nameValue in nameValues )
{
string[] nameAndValue = nameValue.Split( new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries );
writer.AddAttribute( HtmlTextWriterAttribute.Class, "controls controls-row" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
writer.WriteLine();
// Write Name
writer.AddAttribute( HtmlTextWriterAttribute.Class, "span3 key-value-key" );
writer.AddAttribute( HtmlTextWriterAttribute.Type, "text" );
writer.AddAttribute( HtmlTextWriterAttribute.Value, nameAndValue.Length >= 1 ? nameAndValue[0] : string.Empty );
writer.AddAttribute( "placeholder", "Key" );
writer.RenderBeginTag( HtmlTextWriterTag.Input );
writer.RenderEndTag();
writer.Write( " " );
writer.WriteLine();
// Write Value
if ( values == null )
{
writer.AddAttribute( HtmlTextWriterAttribute.Class, "span4 key-value-value" );
writer.AddAttribute( HtmlTextWriterAttribute.Type, "text" );
writer.AddAttribute( "placeholder", "Value" );
writer.AddAttribute( HtmlTextWriterAttribute.Value, nameAndValue.Length >= 2 ? nameAndValue[1] : string.Empty );
writer.RenderBeginTag( HtmlTextWriterTag.Input );
writer.RenderEndTag();
}
else
{
DropDownList ddl = new DropDownList();
ddl.AddCssClass( "key-value-value" );
ddl.DataTextField = "Name";
ddl.DataValueField = "Id";
ddl.DataSource = values;
ddl.DataBind();
ddl.Items.Insert(0, new ListItem( string.Empty, string.Empty ) );
if ( nameAndValue.Length >= 2 )
{
ddl.SelectedValue = nameAndValue[1];
}
ddl.RenderControl( writer );
}
writer.Write( " " );
writer.WriteLine();
// Write Remove Button
writer.AddAttribute( HtmlTextWriterAttribute.Class, "btn key-value-remove" );
writer.AddAttribute( HtmlTextWriterAttribute.Href, "#" );
writer.RenderBeginTag( HtmlTextWriterTag.A );
writer.AddAttribute(HtmlTextWriterAttribute.Class, "fa fa-minus-circle");
writer.RenderBeginTag( HtmlTextWriterTag.I );
writer.RenderEndTag();
writer.RenderEndTag();
writer.WriteLine();
writer.RenderEndTag();
writer.WriteLine();
}
writer.RenderEndTag();
writer.WriteLine();
writer.AddAttribute( HtmlTextWriterAttribute.Class, "btn key-value-add" );
writer.AddAttribute( HtmlTextWriterAttribute.Href, "#" );
writer.RenderBeginTag( HtmlTextWriterTag.A );
writer.AddAttribute(HtmlTextWriterAttribute.Class, "fa fa-plus-circle");
writer.RenderBeginTag( HtmlTextWriterTag.I );
writer.RenderEndTag();
writer.RenderEndTag();
writer.WriteLine();
writer.RenderEndTag();
//.........这里部分代码省略.........
示例5: RenderEntityFieldsControls
/// <summary>
/// Renders the entity fields controls.
/// </summary>
/// <param name="entityType">Type of the entity.</param>
/// <param name="filterControl">The filter control.</param>
/// <param name="writer">The writer.</param>
/// <param name="entityFields">The entity fields.</param>
/// <param name="ddlEntityField">The DDL entity field.</param>
/// <param name="propertyControls">The property controls.</param>
/// <param name="propertyControlsPrefix">The property controls prefix.</param>
public void RenderEntityFieldsControls( Type entityType, FilterField filterControl, HtmlTextWriter writer, List<EntityField> entityFields,
DropDownList ddlEntityField, List<Control> propertyControls, string propertyControlsPrefix )
{
string selectedEntityField = ddlEntityField.SelectedValue;
writer.AddAttribute( "class", "row js-filter-row" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
writer.AddAttribute( "class", "col-md-3" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
ddlEntityField.AddCssClass( "entity-property-selection" );
ddlEntityField.RenderControl( writer );
writer.RenderEndTag();
writer.AddAttribute( "class", "col-md-9" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
// generate result for "none"
StringBuilder sb = new StringBuilder();
string lineFormat = @"
case {0}: {1}; break;";
int fieldIndex = 0;
sb.AppendFormat( lineFormat, fieldIndex, "result = ''" );
fieldIndex++;
// render empty row for "none"
writer.AddAttribute( "class", "row field-criteria" );
writer.RenderBeginTag( HtmlTextWriterTag.Div );
writer.RenderEndTag(); // row
foreach ( var entityField in entityFields )
{
string controlId = string.Format("{0}_{1}", propertyControlsPrefix, entityField.Name );
var control = propertyControls.FirstOrDefault( c => c.ID == controlId );
if ( control != null )
{
if ( entityField.Name != selectedEntityField )
{
if ( control is HtmlControl )
{
( (HtmlControl)control ).Style["display"] = "none";
}
else if ( control is WebControl )
{
( (WebControl)control ).Style["display"] = "none";
}
}
control.RenderControl( writer );
string clientFormatSelection = entityField.FieldType.Field.GetFilterFormatScript( entityField.FieldConfig, entityField.Title );
if ( clientFormatSelection != string.Empty )
{
sb.AppendFormat( lineFormat, fieldIndex, clientFormatSelection );
}
fieldIndex++;
}
}
writer.RenderEndTag(); // col-md-9
writer.RenderEndTag(); // row
string scriptFormat = @"
function {0}PropertySelection($content){{
var sIndex = $('select.entity-property-selection', $content).find(':selected').index();
var $selectedContent = $('div.field-criteria', $content).eq(sIndex);
var result = '';
switch(sIndex) {{
{1}
}}
return result;
}}
";
string script = string.Format( scriptFormat, entityType.Name, sb.ToString() );
ScriptManager.RegisterStartupScript( filterControl, typeof( FilterField ), entityType.Name + "-property-selection", script, true );
script = @"
$('select.entity-property-selection').change(function(){
var $parentRow = $(this).closest('.js-filter-row');
$parentRow.find('div.field-criteria').hide();
$parentRow.find('div.field-criteria').eq($(this).find(':selected').index()).show();
});";
// only need this script once per page
ScriptManager.RegisterStartupScript( filterControl.Page, filterControl.Page.GetType(), "entity-property-selection-change-script", script, true );
//.........这里部分代码省略.........