NET:Checkboxlist,Dropdownlist 添加ToolTip說明

來源:互聯網
上載者:User

標籤:tooltip   c#   

  • ToolTip屬性:

ToolTip 類 (System.Windows.Controls)? 

表示建立彈出項的控制項,該彈出項可顯示介面中元素的相關資訊。命名空間: System.Windows.Controls 程式集: PresentationFramework 

ToolTip 類 (System.Windows.Forms)? 

表示一個長方形的小快顯視窗,該視窗在使用者將指標懸停在一個控制項上時顯示有關該控制項用途的簡短說明。 

以上摘自 MSDN官網。


  • 一般的Label  

其ID可以直接綁定 ToolTip屬性,如

DataTable dt = workLogic.GetPersonID(PersonId);//DataTable dt = new DataTable();StringBuilder sbName = new StringBuilder();StringBuilder sbSNO = new StringBuilder(); sbName.Append(dr["USER_CNAME"].ToString().Trim() + ",");this.labelID.text = sbName;this.laeblID.ToolTip = sbSNO ;

  • DropDownList:

myDropDownList.Items[0].Attributes.Add("title", "text").
  • CheckBoxList:

foreach (ListItem toolTip in <span style="font-weight: bold;">CheckBoxList</span>.Items)                        {                            DataRow[] dRows =<span style="font-family: Arial, Helvetica, sans-serif;">CheckBoxListID</span>.Select("USER_CNAME = '" + toolTip.Text.ToString() +"'");                            if(dRows != null && dRows.Length>0)                            {                                                                //this.<span style="font-family: Arial, Helvetica, sans-serif;">CheckBoxListID</span>.Items[i].Attributes.Add("","");                                this.<span style="font-family: Arial, Helvetica, sans-serif;">CheckBoxListID</span>.Items[0].Attributes.Add("title", dRows[0]["USER_NAME"].ToString());                                toolTip.Attributes.Add("title", dRows[0]["USER_NAME"].ToString());                            }                                                                            }




foreach (ListItem item in ckl_EditRole.Items)    {        item.Attributes["title"] = GetRoleTooltip(item.Value);    }



  • Checkboxlist,Dropdownlist, RedioButtonlist  資料繫結


一、DropDownList:
1、選項值儲存到資料庫:
   Hashtable ht=new Hashtable();//這裡用Hashtable
   ht.Add("欄位名",DropDownListID.SelectedItem.Text.ToString());//儲存選項Text
   ht.Add("欄位名",DropDownListID.SelectedItem.Value.ToString());//儲存選項Value


2、選項值由資料庫綁定到DropDownList:
   首先DropDownListID.ClearSelection();//清除選項
    DropDownListID.Items.FindByText(dr["欄位名"].ToString()).Selected = true;//選項Text
    DropDownListID.Items.FindByValue(dr["欄位名"].ToString()).Selected = true;//選項Value


二、RadioButtonList:
1、選項值儲存到資料庫(同DropDownList):
   Hashtable ht=new Hashtable();//這裡用Hashtable
   ht.Add("欄位名",RadioButtonListID.SelectedItem.Text.ToString());//儲存選項Text
   ht.Add("欄位名",RadioButtonListID.SelectedItem.Value.ToString());//儲存選項Value


2、選項值由資料庫綁定到RadioButtonList
   string SelectItem = dr["欄位名"].ToString();//將資料庫中的選項值從DataRow中讀出賦給變數SelectItem
   for (int i = 0; i < RadioButtonListID.Items.Count; i++)
   {//用for迴圈判斷那項被選種
       if (RadioButtonListID.Items[i].Text == SelectItem)RadioButtonListID.Items[i].Selected = true;
   }


三、CheckBoxList:
1、選項值儲存到資料庫
   string str1= "";//聲明一個變數來接受選項
   for (int i = 0; i < CheckBoxListID.Items.Count; i++)
   {//用for迴圈將所有選項用","隔開串連起來
        if (CheckBoxListID.Items[i].Selected)
        {
            str1= str1+ CheckBoxListID.Items[i].Value + ",";//選項後加","隔開
        }
   }
   ht.Add("欄位名",SelectItem.ToString());


2、選項值由資料庫綁定到CheckBoxList
   string SelectItem = dr["欄位名"].ToString();
   string[] arrStr = SelectItem.Split(",");//欄位是以","隔開
   foreach (string str in arrStr)
   {
       for (int i = 0; i <CheckBoxListID.Items.Count; i++)
       {
          if (this.CheckBoxListID.Items[i].Value == str)
          {
             this.CheckBoxListID.Items[i].Selected = true;
          }
       }
   }


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.