2011-11-14 13 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(); 
    } 

Para cada elemento, la información sobre herramientas es diferente, la información sobre herramientas de administración crea usuarios y para los usuarios la información sobre herramientas crea un mensaje. ¿Cómo puedo agregar información sobre herramientas para cada elemento dentro de la casilla de verificaciónCómo agregar información sobre herramientas para Checkboxlist para cada elemento en asp.net

+0

Deberías hacer una pregunta en el cuerpo. – Joshua

+0

Sí, he cambiado mi pregunta, gracias – Mark

Respuesta

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

Utilice la propiedad sobre herramientas:

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

Es esto lo que está pidiendo?

Si desea actualizar la información sobre herramientas para cada artículo, entonces usted necesita para tratarlos por separado:

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

Por cada elemento, la información sobre herramientas es diferente, la información sobre herramientas de administración crea el usuario y para los usuarios la información sobre herramientas es un mensaje de creación – Mark

0

Puede utilizar bucle PreRender event-- sobre los artículos (debe ser ListItems), y puede establecer un atributo html para el título en función de los valores de la casilla de verificación.

En los casos en que deseo tener mucho control sobre las casillas de verificación, podría estar a favor de poner una casilla de verificación en un repetidor, pero podría no ser necesario aquí.

0

Puede escribir el siguiente fragmento de código en el método de carga de la página: chkbox.Items [0] .Attributes.Add ("Título", "Administrador"); chkbox.ToolTip = "Administrador";

chkbox.Items [1] .Attributes.Add ("Título", "Usuario"); chkbox.ToolTip = "Usuario";

0

Esto es lo que uso, con más funciones, como hacer que ListItem parezca un botón de enlace.

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

Así que, en efecto, estoy colocando una información sobre herramientas que es único sobre la base de los datos de la DatSource y cambiar la apariencia de la ListItem a subrayado azul.

Cuestiones relacionadas