I want to bind tool tip to drop down list item. My code is
protected void ddl_DataBound(object sender, EventArgs e)
{
if (ViewState["HeadToolTip"] != null)
{
DataTable dt = ViewState["HeadToolTip"] as DataTable;
DropDownList ddl = sender as DropDownList;
if (ddl != null)
{
foreach (ListItem li in ddl.Items)
{
DataRow drow = dt.Rows.Cast<DataRow>().FirstOrDefault(x => x.Field<string>("HeadCode") == li.Value.ToString());
if (drow != null)
{
li.Attributes["title"] = drow["ToolTip"].ToString();// li.Text;
}
}
}
}
}
It is working but after selection of any item tool tip is removed from all item list.
You are setting tooltip on DataBound
, it might be possible when you are not binding Data within Load or SelectedIndexChange
, when you select an item, 2 things occur, SelectedIndexChange
event fires and then Page_Load event fires, you are not binding in either one of them I think. That's why somehow, tooltip
not working. You should place your tooltip
code within a function and call that function from Page_Load or SelectedIndexChange
, so the tooltip
will again be binded with DropDownList
Hope it solves your issue. Regards!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.