开发者

CheckBox ToolTip Database

开发者 https://www.devze.com 2023-02-13 11:00 出处:网络
Ok, so I need some help here. I have a table AgileFactors in my database that has the following fields: AgileFactorID, Name and Description. I am using a checkboxlist to bind the Name as the DataTextF

Ok, so I need some help here. I have a table AgileFactors in my database that has the following fields: AgileFactorID, Name and Description. I am using a checkboxlist to bind the Name as the DataTextField, and the AgileFactorID as the DataValueField. What I would like to do is use the Description field from the db as the tooltip on hover for the info icon which I am displaying next to each checkbox. Please have a look at my code below. At the moment, I am passing in a long string within the span tags, which is pointless. Could anyone help me make sure that the tooltip is retrieved from the db? Many thanks in advance!

"SELECT Name, AgileFactorID, Description FROM AgileFactors"

agile_factors.DataSource = ds2;
agile_factors.DataTextField = "Name";
agile_factors.DataValueField = "AgileFactorID";
agile_factors.DataBind();


prot开发者_Python百科ected void agilefactors_DataBound(object sender, EventArgs e)
{

    var checkBox = sender as CheckBoxList;
    if (checkBox != null)
    {

        foreach (ListItem listItem in checkBox.Items)
        {

            listItem.Text = string.Format("{0} <span class='link'><a href='javascript: void(0)'><font face='verdana,arial,helvetica' size='2'><img src='{1}' Height='15' Width='15' /></font><span><b>Project Duration:</b><br/>Ideally, the project should be close to 6 months: much shorter means less iterations, and much longer tends towards long term planning.</span></a></span>", listItem.Text, GetImageFor(listItem.Text));

        }
    }
}

private string GetImageFor(string text)
{

    // return image url for check box based on text. 
    switch (text)
    {
        case "Project Duration": return "images/iicon.gif";
        case "Customer Involvement": return "images/iicon.gif";
        case "Acceptance of Change": return "images/iicon.gif";
        case "Team Size": return "images/iicon.gif";
        case "Skill of Team": return "images/iicon.gif";
        case "Organisational and Reporting Structure": return "images/iicon.gif";
        case "Process": return "images/iicon.gif";
        case "Documentation Requirements": return "images/iicon.gif";
        case "Layout of Workspace": return "images/iicon.gif";
        case "Empowered Team": return "images/iicon.gif";
        default: return null;
    }
}


Just as you have a function to GetImageFor, create another function to "GetTooltip". Pull the tooltip like you did the other fields and assign it to the tooltip property.

Edit

You really have all the code, all you have to do is do it. I wont do the database side for you because you yourself can do that and you've demonstrated that here.

But to add tooltips here you go:

 int i = 0;

            foreach(ListItem l in this.CheckBoxList1.Items)
            {
                i++;
                l.Attributes["title"] = "Tooltip " + i.ToString();
            }

Here is a screen shot of the result.

CheckBox ToolTip Database


Format as you need, but here you go - one way

protected void agilefactors_DataBound(object sender, EventArgs e) 
{ 
    var checkBox = sender as CheckBoxList; 
    if (checkBox != null) 
    { 
        foreach (ListItem listItem in checkBox.Items) 
        {                
            listItem.Text = string.Format("{0} <span class='link'><a href='javascript: void(0)'><font face='verdana,arial,helvetica' size='2'><img src='{1}' Height='15' Width='15' alt='{2}' /></font><span><b>Project Duration:</b><br/>Ideally, the project should be close to 6 months: much shorter means less iterations, and much longer tends towards long term planning.</span></a></span>", listItem.Text, GetImageFor(listItem.Text), GetToolTip(listItem.Value));
        } 
    } 
}

private string GetToolTip(string value)
{
    var x = (from y in ds2.AsEnumerable()
             where y["AgileFactorID"] == value
             select y["description"]).FirstOrDefault();

    return x.ToString();
}

You're going to need to fix up what you have, but this should help.

0

精彩评论

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

关注公众号