2011-11-14 15 views
7
<asp:CheckBoxList ID="ckl_EditRole" DataValueField="RoleName" runat="server"> 
            </asp:CheckBoxList> 
public void BindListBoxPermission(int field) 
    { 
     MySqlCommand command = new MySqlCommand(); 
     DataSet ds = new DataSet(); 
     int newOrgID = field; 
     string MysqlStatement = "SELECT RoleName from tbl_Role Where RoleID >1 order by RoleID desc"; 
     MySqlParameter[] param = new MySqlParameter[0]; 
     ds = server.ExecuteQuery(CommandType.Text, MysqlStatement, param); 
     ckl_EditRole.DataSource = ds; 
     ckl_EditRole.DataBind(); 
    } 

Đối với mỗi mục chú giải công cụ khác nhau, cho chú giải công cụ quản trị được tạo ra và chú giải công cụ của người dùng là tạo thông báo. Làm thế nào tôi có thể thêm tooltip cho từng hạng mục bên trong kiểm tra hộpCách thêm chú giải công cụ cho Danh sách kiểm tra cho mỗi mục trong asp.net

+0

Bạn thực sự nên đặt câu hỏi trong nội dung. – Joshua

+0

Vâng tôi đã thay đổi câu hỏi của mình, cảm ơn – Mark

Trả lời

14
protected void Page_PreRender(object sender, EventArgs e) 
{ 
    foreach (ListItem item in ckl_EditRole.Items) 
    { 
     item.Attributes["title"] = GetRoleTooltip(item.Value); 
    } 
} 

private static string GetRoleTooltip(string p) 
{ 
    // here is your code to get appropriate tooltip message depending on role 
} 
0

Sử dụng thuộc tính ToolTip:

<asp:CheckBoxList ID="ckl_EditRole" DataValueField="RoleName" runat="server" ToolTip="Roles"> 
</asp:CheckBoxList> 

Đây có phải là những gì bạn đang yêu cầu?

Nếu bạn muốn cập nhật ToolTip cho từng hạng mục thì bạn cần phải đối xử với họ một cách riêng biệt:

for (int i = 0; i < ckl_EditRole.Items.Count; i++) 
    ckl_EditRole.Items[i].Attributes["title"] = "custom Tooltip"; 
+0

Đối với mỗi mục chú giải công cụ khác nhau, cho chú giải công cụ quản trị là tạo người dùng và chú giải công cụ của người dùng là tạo thông báo – Mark

0

Bạn có thể sử dụng vòng lặp PreRender event-- qua các mục (nên ListItems), và bạn có thể đặt thuộc tính html cho tiêu đề dựa trên giá trị của hộp kiểm.

Trong trường hợp tôi muốn có nhiều quyền kiểm soát hộp kiểm, tôi có thể ưu tiên đặt hộp kiểm trong bộ lặp - nhưng điều đó có thể không cần thiết ở đây.

0

Bạn có thể viết đoạn mã sau đây vào phương pháp tải trang: chkbox.Items [0] .Attributes.Add ("Title", "Admin"); chkbox.ToolTip = "Quản trị";

chkbox.Items [1] .Attributes.Add ("Title", "User"); chkbox.ToolTip = "Người dùng";

0

Đây là những gì tôi sử dụng, với nhiều tính năng hơn, như làm cho ListItem trông giống như một nút liên kết.

protected void FormatPaskWeeksPerStudentRow(GridViewRow gvRow) 
    { 
      SqlDataSource sdsTETpastWeeks = (SqlDataSource)gvRow.FindControl("sdsTETpastWeeks"); 
      sdsTETpastWeeks.SelectParameters["StudentID"].DefaultValue = hfStudentID.Value.ToString(); 
      if (sdsTETpastWeeks != null) 
      { 
       CheckBoxList cbl1 = (CheckBoxList)gvRow.FindControl("listWeeksTracking"); 
       if (cbl1 != null) 
       { 
        cbl1.DataBind(); 

        foreach (ListItem litem in cbl1.Items) 
        { 
         //disable the checkbox for now 
         litem.Enabled = false; 

         //see if any of the past weeks (excluding this week) needs to be highlighted as a hyperlink to show past comments 
         //get the Tracking value. If set, then mark the checkbox as Selected or Checked 
         DataSourceSelectArguments dss = new DataSourceSelectArguments(); 
         DataView dv = sdsTETpastWeeks.Select(dss) as DataView; 
         DataTable dt = dv.ToTable() as DataTable; 
         if (dt != null) 
         { 
          //this loops through ALL the weeks available to the student, for this block 
          //it tries to match it against the current ListItem for the week it's loading and determines if they match 
          //if so then mark the item selected (checked=true) if the value in the sub query says it's true 
          foreach (DataRow dr in dt.Rows) 
          { 
           if (litem.Text == dr.ItemArray[0].ToString() && litem.Text != ddlWeekNo.SelectedItem.Text) 
           { 
            if ((bool)dr.ItemArray[1]) 
             litem.Selected = true; 

            //for those that were not ticked in prior weeks, make a ToolTip with the text/comment made in that week and underscore the week number 
            else 
            { 
             litem.Attributes["title"] = dr.ItemArray[2].ToString(); 
             litem.Attributes.Add("style", "color:Blue;font-style:italic;text-decoration:underline;"); 
            } 
           } 
          } 
         } 
        } 
       } 
      } 
} 

Vì vậy, có hiệu lực Tôi đặt Chú giải công cụ duy nhất dựa trên dữ liệu từ DatSource và tôi thay đổi giao diện của ListItem thành gạch dưới màu xanh lam.