2011-02-24 81 views
2

好的,所以我需要一些幫助。我在我的數據庫中有一個表格AgileFactors,它具有以下字段:AgileFactorID,Name和Description。我使用checkboxlist將Name作爲DataTextField,將AgileFactorID作爲DataValueField進行綁定。我想要做的是使用db中的Description域作爲懸停時的工具提示,以顯示每個複選框旁邊顯示的信息圖標。請看下面我的代碼。此刻,我在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; 
    } 
} 

回答

1

就像你有一個GetImageFor函數一樣,創建另一個函數來「GetTooltip」。 像其他字段一樣提取工具提示並將其分配給工具提示屬性。

編輯

你真的有所有的代碼,所有你所要做的就是去做。我不會爲你做數據庫端,因爲你自己可以做到這一點,你已經證明了這一點。

但這裏要補充的工具提示你去:

int i = 0; 

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

下面是結果的屏幕截圖。 enter image description here

+0

你能告訴我該怎麼做嗎?我非常感謝它...... – user618616 2011-02-24 19:37:35

+0

如果真的需要你的幫助,請點擊這裏。我認爲使用這種方法是可行的。我真的不知道如何從數據庫中讀取描述,但是......請告訴我嗎? – user618616 2011-02-24 20:55:31

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(); 
} 

你將需要修復了,你有什麼,但這應該幫助的一種方式。

+0

僅僅使用listitem類的屬性並指定title屬性不是更簡單嗎? – JonH 2011-02-24 20:10:12

+0

當然 - 但我試圖堅持他所擁有的東西,而不是重寫,以防他需要鏈接中的文本等等。 – TheGeekYouNeed 2011-02-24 20:26:04