如何为asp.net中的每个项目添加复选框列表的工具提示

发布于 2024-12-15 13:42:11 字数 723 浏览 3 评论 0原文

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

对于每个项目的工具提示都是不同的,对于管理工具提示是创建用户,对于用户工具提示是创建消息。如何为复选框内的每个项目添加工具提示

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

For each item tooltip is different, for admin tooltip is creates user and for users tooltip is creates message. How can I add tooltip for each item inside the check box

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

飞烟轻若梦 2024-12-22 13:42:11
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
}
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
}
樱花细雨 2024-12-22 13:42:11

使用 ToolTip 属性:

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

这是您要问的吗?

如果您想更新每个项目的工具提示,那么您需要单独处理它们:

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

Use the ToolTip property:

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

Is this what you are asking?

If you want to update the ToolTip for each item then you need to treat them separately:

for (int i = 0; i < ckl_EditRole.Items.Count; i++)
   ckl_EditRole.Items[i].Attributes["title"] = "custom Tooltip";
烟花肆意 2024-12-22 13:42:11

您可以使用 PreRender 事件——循环遍历项目(应该是 ListItems),并且可以根据复选框的值设置标题的 html 属性。

如果我想对复选框进行大量控制,我可能会倾向于在中继器中放置一个复选框 - 但这在这里可能没有必要。

You can use PreRender event-- loop over the items (should be ListItems), and you can set an html attribute for title based on the values of the checkbox.

In cases where I want to have alot of control over the checkboxes, I might favor putting a checkbox in a repeater-- but that might not be necessary here.

一张白纸 2024-12-22 13:42:11

您可以在页面加载方法上编写以下代码片段:
chkbox.Items[0].Attributes.Add("标题", "管理员");
chkbox.ToolTip = "管理员";

chkbox.Items[1].Attributes.Add("标题", "用户");
chkbox.ToolTip = "用户";

You can write the following snippet of code on the page load method:
chkbox.Items[0].Attributes.Add("Title", "Admin");
chkbox.ToolTip = "Admin";

chkbox.Items[1].Attributes.Add("Title", "User");
chkbox.ToolTip = "User";

拔了角的鹿 2024-12-22 13:42:11

这就是我使用的,具有更多功能,例如使 ListItem 看起来像链接按钮。

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

因此,实际上,我根据 DatSource 中的数据放置了一个唯一的工具提示,并将 ListItem 的外观更改为蓝色下划线。

This is what I use, with more features, like making the ListItem look like a linkbutton.

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

So in effect I am placing a ToolTip that's unique based on the data from the DatSource and I change the appearance of the ListItem to blue underline.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文