本文介绍了如何为下拉列表添加工具提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何为下拉列表添加工具提示...其中包含来自后端的数据....
这是我正在使用的代码
Hi,
how to add ToolTip for drop down list... which contain data from backend....
this is the code i am using
private void AttachTooltipForDropdowns(DropDownList ddlTarget)
{
for (int i = 0; i < ddlTarget.Items.Count; i++)
{
ddlTarget.Items[i].Attributes.Add("title", ddlTarget.Items[i].Text);
}
}
<br />
protected void Page_Prerender(object sender, EventArgs e)
{
AttachTooltipForDropdowns(ddlf1);
AttachTooltipForDropdowns(ddlf2);
}
ddlf1,ddlf2是ddl的ID,但不起作用.
有价值的建议和解决方案... plz
ddlf1,ddlf2 are the ID ''s of the ddl, but it is not working.
valuable suggestion and solutions... plz
推荐答案
private void AttachTooltipForDropdowns(ref DropDownList ddlTarget)
{
for (int i = 0; i < ddlTarget.Items.Count; i++)
{
ddlTarget.Items[i].Attributes.Add("title", ddlTarget.Items[i].Text);
}
}
protected void Page_Prerender(object sender, EventArgs e)
{
AttachTooltipForDropdowns(ref ddlf1);
AttachTooltipForDropdowns(ref ddlf2);
}
protected void Page_InitComplete(object sender, EventArgs e)
{
drp.PreRender += new EventHandler(DropDown_PreRender);
}
public void DropDown_PreRender(object sender, EventArgs e)
{
DropDownList ddl = sender as DropDownList;
if (ddl != null)
{
foreach (ListItem li in ddl.Items)
{
// setting text value of item as tooltip
li.Attributes.Add("title", li.Text);
}
}
}
{
这篇关于如何为下拉列表添加工具提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!