本文整理汇总了C#中System.Web.UI.WebControls.DropDownList.RenderControl方法的典型用法代码示例。如果您正苦于以下问题:C# DropDownList.RenderControl方法的具体用法?C# DropDownList.RenderControl怎么用?C# DropDownList.RenderControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.WebControls.DropDownList
的用法示例。
在下文中一共展示了DropDownList.RenderControl方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: RenderFooter
protected override void RenderFooter(HtmlTextWriter writer) {
writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "4px");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
DropDownList zonesDropDownList = new DropDownList();
zonesDropDownList.ClientIDMode = ClientIDMode.AutoID;
zonesDropDownList.ID = ZonesID;
// Populate the DropDownList
if (DesignMode) {
// Add sample zone to dropdown
zonesDropDownList.Items.Add(SR.GetString(SR.Zone_SampleHeaderText));
}
else {
if (WebPartManager != null && WebPartManager.Zones != null) {
foreach (WebPartZoneBase zone in WebPartManager.Zones) {
if (zone.AllowLayoutChange) {
Debug.Assert(!String.IsNullOrEmpty(zone.ID));
ListItem item = new ListItem(zone.DisplayTitle, zone.ID);
if (String.Equals(zone.ID, _selectedZoneID, StringComparison.OrdinalIgnoreCase)) {
item.Selected = true;
}
zonesDropDownList.Items.Add(item);
}
}
}
}
LabelStyle.AddAttributesToRender(writer, this);
// Only render the "for" attribute if we are going to render the associated DropDownList (VSWhidbey 541458)
if (zonesDropDownList.Items.Count > 0) {
writer.AddAttribute(HtmlTextWriterAttribute.For, zonesDropDownList.ClientID);
}
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write(SelectTargetZoneText);
writer.RenderEndTag();
// Render before the DropDownList (VSWhidbey 77709)
writer.Write(" ");
zonesDropDownList.ApplyStyle(EditUIStyle);
// Do not render empty DropDownList (VSWhidbey 534498)
if (zonesDropDownList.Items.Count > 0) {
zonesDropDownList.RenderControl(writer);
}
writer.Write(" ");
RenderVerbs(writer);
writer.RenderEndTag(); // Div
}
示例3: 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++;
}
//.........这里部分代码省略.........
示例4: DropDownPopulate
private string DropDownPopulate(HttpContext context)
{
DropDownList list = new DropDownList();
list.ID = "FoodUnitList";
using (var conn = new SqlConnection("Server=(local);DataBase=Nutrition;Integrated Security=SSPI"))
{
using (var command = new SqlCommand("dbo.Food_Units_Get", conn)
{
CommandType = CommandType.StoredProcedure
})
{
command.Parameters.Add("@Food_Key", SqlDbType.Int);
command.Parameters["@Food_Key"].Value = context.Request.Params["FoodKey"];
conn.Open();
var reader = command.ExecuteReader(CommandBehavior.CloseConnection);
list.DataSource = reader;
list.DataTextField = "Unit_Name";
list.DataValueField = "Unit_Key";
list.DataBind();
conn.Close();
using (var command2 = new SqlCommand("dbo.Food_Unit_Get", conn)
{
CommandType = CommandType.StoredProcedure
})
{
conn.Open();
command2.Parameters.Add("@Food_Key", SqlDbType.Int);
command2.Parameters["@Food_Key"].Value = context.Request.Params["FoodKey"];
// Create parameter with Direction as Output (and correct name and type)
SqlParameter outputIdParam = new SqlParameter("@Unit_Key", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
command2.CommandType = CommandType.StoredProcedure;
command2.Parameters.Add(outputIdParam);
command2.ExecuteNonQuery();
list.SelectedValue = outputIdParam.Value.ToString();
conn.Close();
}
}
}
StringWriter theStringWriter = new StringWriter();
HtmlTextWriter theHtmlTextWriter = new HtmlTextWriter(theStringWriter);
// Render the table row control into the writer
list.RenderControl(theHtmlTextWriter);
// Return the string via the StringWriter
return theStringWriter.ToString();
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
int? foodKey = null;
int? unitKey = null;
this.tableHeader.Attributes.Add("nutritionhistorykey", Request.QueryString["Nutrition_History_Key"]);
this.tableHeader.Attributes.Add("adddatefrom", Request.QueryString["Add_Date_From"]);
this.tableHeader.Attributes.Add("adddateto", Request.QueryString["Add_Date_To"]);
using (var conn = new SqlConnection("Server=(local);DataBase=Nutrition;Integrated Security=SSPI"))
{
using (var command = new SqlCommand("dbo.Nutrition_Profile_Entry_Get", conn)
{
CommandType = CommandType.StoredProcedure
})
{
conn.Open();
command.Parameters.Add("@User_Key", SqlDbType.Int);
command.Parameters["@User_Key"].Value = 1; //Hard-coded to my User_Key for now
command.Parameters.Add("@Nutrition_History_Key", SqlDbType.Int);
command.Parameters["@Nutrition_History_Key"].Value = Request.QueryString["Nutrition_History_Key"];
var reader = command.ExecuteReader(CommandBehavior.CloseConnection);
if (reader.HasRows)
{
reader.Read();
foodKey = int.Parse(reader["Food_Key"].ToString());
unitKey = int.Parse(reader["Unit_Key"].ToString());
var cell = new TableHeaderCell { Text = reader["Name"].ToString(), ColumnSpan = 2 };
cell.Style.Add("border-bottom-width", "2px");
cell.Style.Add("border-bottom-style", "solid");
cell.Style.Add("border-bottom-color", "#8dbdd8");
tableHeader.Cells.Add(cell);
this.FoodQuantityDisplay.Value = reader["Quantity"].ToString();
DateTime datetime = DateTime.Parse(reader["Add_Date"].ToString());
string date = datetime.ToString("yyyy-MM-dd");
this.AddDateDisplay.Value = date;
this.CaloriesDisplay.InnerHtml = reader["Calories"].ToString();
this.WaterDisplay.InnerHtml = reader["Water"].ToString();
this.ProteinDisplay.InnerHtml = reader["Protein"].ToString();
this.LipidDisplay.InnerHtml = reader["Lipid"].ToString();
this.CarbohydrateDisplay.InnerHtml = reader["Carbohydrate"].ToString();
this.FiberDisplay.InnerHtml = reader["Fiber"].ToString();
this.SugarDisplay.InnerHtml = reader["Sugar"].ToString();
this.CalciumDisplay.InnerHtml = reader["Calcium"].ToString();
this.IronDisplay.InnerHtml = reader["Iron"].ToString();
}
conn.Close();
}
}
if (foodKey.HasValue)
{
DropDownList list = new DropDownList();
list.ID = "UnitDisplay";
using (var conn = new SqlConnection("Server=(local);DataBase=Nutrition;Integrated Security=SSPI"))
{
using (var command = new SqlCommand("dbo.Food_Units_Get", conn)
{
CommandType = CommandType.StoredProcedure
})
{
command.Parameters.Add("@Food_Key", SqlDbType.Int);
command.Parameters["@Food_Key"].Value = foodKey.Value;
conn.Open();
var reader = command.ExecuteReader(CommandBehavior.CloseConnection);
list.DataSource = reader;
list.DataTextField = "Unit_Name";
list.DataValueField = "Unit_Key";
list.DataBind();
list.SelectedValue = unitKey.Value.ToString();
conn.Close();
}
}
StringWriter theStringWriter = new StringWriter();
HtmlTextWriter theHtmlTextWriter = new HtmlTextWriter(theStringWriter);
// Render the table row control into the writer
list.RenderControl(theHtmlTextWriter);
// Return the string via the StringWriter
this.UnitDisplayHolder.InnerHtml = theStringWriter.ToString();
}
}
示例6: 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 );
//.........这里部分代码省略.........
示例7: 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();
//.........这里部分代码省略.........
示例8: RenderFooter
protected override void RenderFooter(HtmlTextWriter writer)
{
writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "4px");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
DropDownList list = new DropDownList {
ClientIDMode = ClientIDMode.AutoID,
ID = this.ZonesID
};
if (base.DesignMode)
{
list.Items.Add(System.Web.SR.GetString("Zone_SampleHeaderText"));
}
else if ((base.WebPartManager != null) && (base.WebPartManager.Zones != null))
{
foreach (WebPartZoneBase base2 in base.WebPartManager.Zones)
{
if (base2.AllowLayoutChange)
{
ListItem item = new ListItem(base2.DisplayTitle, base2.ID);
if (string.Equals(base2.ID, this._selectedZoneID, StringComparison.OrdinalIgnoreCase))
{
item.Selected = true;
}
list.Items.Add(item);
}
}
}
base.LabelStyle.AddAttributesToRender(writer, this);
if (list.Items.Count > 0)
{
writer.AddAttribute(HtmlTextWriterAttribute.For, list.ClientID);
}
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write(this.SelectTargetZoneText);
writer.RenderEndTag();
writer.Write(" ");
list.ApplyStyle(base.EditUIStyle);
if (list.Items.Count > 0)
{
list.RenderControl(writer);
}
writer.Write(" ");
this.RenderVerbs(writer);
writer.RenderEndTag();
}
示例9: 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 );
//.........这里部分代码省略.........