好的,所以我需要一些帮助。我的数据库中有一个表AgileFactors,它包含以下字段:AgileFactorID,Name和Description。我使用checkboxlist将Name绑定为DataTextField,将AgileFactorID绑定为DataValueField。我想要做的是使用数据库中的描述字段作为悬停的工具提示,我将在每个复选框旁边显示信息图标。请看下面的代码。目前,我在span标签内传入一个长字符串,这是毫无意义的。任何人都可以帮我确保从数据库中检索工具提示吗?非常感谢提前!
"SELECT Name, AgileFactorID, Description FROM AgileFactors"
agile_factors.DataSource = ds2;
agile_factors.DataTextField = "Name";
agile_factors.DataValueField = "AgileFactorID";
agile_factors.DataBind();
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' /></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;
}
}
答案 0 :(得分:1)
就像你有一个GetImageFor函数一样,为“GetTooltip”创建另一个函数。 像处理其他字段一样拉出工具提示,并将其分配给工具提示属性。
修改强>
你真的拥有所有代码,你所要做的就是去做。我不会为你做数据库方面,因为你自己可以这样做,你已经证明了这一点。
但是要在这里添加工具提示:
int i = 0;
foreach(ListItem l in this.CheckBoxList1.Items)
{
i++;
l.Attributes["title"] = "Tooltip " + i.ToString();
}
以下是结果的屏幕截图。
答案 1 :(得分:0)
根据需要进行格式化,但是在这里 - 单程
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();
}
你需要修复你拥有的东西,但这应该会有所帮助。