本文介绍了.元素"DropDownListX"不是已知元素“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
对于我的aspx页面,如下所示,我使用了1个类来制作"DropDownListX"控件,但在页面的源代码视图中,我警告元素" DropDownListX"不是已知元素".
在aspx.cs中可以知道控件.
aspx页面如下:
Hello
for my aspx page like below , i have used 1 class for making "DropDownListX" control, but in source view of page , i have warning "Element ''DropDownListX'' is not a known element".
in aspx.cs can know the control.
aspx page is like below:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication11._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownListX runat="server" ID="ddlx" />
<asp:DropDownListX ID="ddlu" runat="server"/>
</div>
</form>
</body>
</html>
aspx.cs如下所示:
aspx.cs is like below:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication11
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ddlx.Items.Insert(0, new ListItem(String.Empty, String.Empty));
ddlx.SelectedIndex = 0;
this.ddlx.AddItemGroup("Administrators");
{
this.ddlx.Items.Add("masoud");
this.ddlx.Items.Add("sedighy");
}
this.ddlx.AddItemGroup("Users");
{
this.ddlx.Items.Add("ahmed");
this.ddlx.Items.Add("mosavi");
}
}
}
}
类DropDownListX''如下所示
class DropDownListX'' is like below
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication11
{
/// <summary>
/// Summary description for DropDownListX
/// </summary>
public class DropDownListX : DropDownList
{
public void AddItemGroup(string groupTitle)
{
this.Items.Add(new ListItem(groupTitle, "$$OPTGROUP$$OPTGROUP$$"));
}
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
{
if (this.Items.Count > 0)
{
bool selected = false;
bool optGroupStarted = false;
for (int i = 0; i < this.Items.Count; i++)
{
ListItem item = this.Items[i];
if (item.Enabled)
{
if (item.Value == "$$OPTGROUP$$OPTGROUP$$")
{
if (optGroupStarted)
writer.WriteEndTag("optgroup");
writer.WriteBeginTag("optgroup");
writer.WriteAttribute("label", item.Text);
writer.Write('>');
writer.WriteLine();
optGroupStarted = true;
}
else
{
writer.WriteBeginTag("option");
if (item.Selected)
{
if (selected)
{
this.VerifyMultiSelect();
}
selected = true;
writer.WriteAttribute("selected", "selected");
}
writer.WriteAttribute("value", item.Value, true);
if (item.Attributes.Count > 0)
{
item.Attributes.Render(writer);
}
if (this.Page != null)
{
this.Page.ClientScript.RegisterForEventValidation(
this.UniqueID,
item.Value);
}
writer.Write('>');
HttpUtility.HtmlEncode(item.Text, writer);
writer.WriteEndTag("option");
writer.WriteLine();
}
}
}
if (optGroupStarted)
{
writer.WriteEndTag("optgroup");
}
}
}
}
}
推荐答案
这篇关于.元素"DropDownListX"不是已知元素“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!