开发者

Extend the DropDown for Item ToolTip,Asp.net,C#

i need to extend the DropDownList For adding toolTip开发者_开发百科 For DropDown Item On mouseOver.

If(Dropdown size is samller than Dropdownlist item then it will be useful for seeing the item as tool tip)

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

which need to be worked as (DataTextField, DataValueField in drop down list) in that class .

tell me any link for ServerControl project sample which resembles my requirement.

I tried using below code but dropdown property itself not working..

namespace 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? 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));
                }
            }
        }

    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜