[英]Extend the DropDown for Item ToolTip,Asp.net,C#
i need to extend the DropDownList For adding toolTip For DropDown Item On mouseOver. 我需要扩展DropDownList,以便在mouseOver上为DropDown项目添加toolTip。
If(Dropdown size is samller than Dropdownlist item then it will be useful for seeing the item as tool tip) 如果(Dropdown大小比Dropdownlist项目小,那么将其视为工具提示将很有用)
For that i came to know, We need to create ServerControl project in VS2008 but i dont know how to add a property like ItemToolTip 为此,我知道,我们需要在VS2008中创建ServerControl项目,但是我不知道如何添加诸如ItemToolTip之类的属性
which need to be worked as (DataTextField, DataValueField in drop down list) in that class . 需要在该类中作为(DataTextField,下拉列表中的DataValueField)工作。
tell me any link for ServerControl project sample which resembles my requirement. 告诉我与我的要求类似的ServerControl项目示例的任何链接。
I tried using below code but dropdown property itself not working.. 我尝试使用下面的代码,但下拉属性本身不起作用。
namespace DropDownItemToolTip 命名空间DropDownItemToolTip
{ {
[DefaultProperty("Text")]
[ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")]
public class ServerControl1 : System.Web.UI.WebControls.DropDownList
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text1
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? "[" + this.ID + "]" : s);
}
set
{
ViewState["Text"] = value;
}
}
protected override void RenderContents(HtmlTextWriter output)
{
output.Write(Text1);
}
}
} }
Send me any sample project link, which done like this.. 给我发送任何示例项目链接,这样做就像是这样。
Why you want to extend the Dropdownlist? 为什么要扩展Dropdownlist? Try adding a Title tag will work right?
尝试添加标题标签会正确吗?
Try this code 试试这个代码
<select>
<option title="this is a long text">Long text</option>
</select>
It will show a this is a long text tooltip on mouseover. 它将显示这是鼠标悬停时的长文本工具提示。
Try this: 尝试这个:
using System.Collections;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Foo
{
[ToolboxData("<{0}:DDL runat=\"server\" />")]
public class DDL : DropDownList
{
[Category("Data"), DefaultValue("")]
public string DataToolTipField
{
get { return (string)(ViewState["DataToolTipField"] ?? string.Empty); }
set { ViewState["DataToolTipField"] = value; }
}
protected override void PerformDataBinding(IEnumerable dataSource)
{
base.PerformDataBinding(dataSource);
string dataToolTipField = this.DataToolTipField;
if (!string.IsNullOrEmpty(dataToolTipField))
{
IEnumerator enumerator = dataSource.GetEnumerator();
for (int i = 0; enumerator.MoveNext(); i++)
{
this.Items[i].Attributes.Add("title", (string)DataBinder.GetPropertyValue(enumerator.Current, dataToolTipField));
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.