asp.net 下拉列表工具提示(标题)奇怪的行为

发布于 2024-09-28 17:42:11 字数 2086 浏览 3 评论 0原文

我使用以下代码隐藏在我的下拉列表中添加了一个“工具提示”:(

        protected void btnAdd_Click(object sender, EventArgs e)
    {
        load_Buttons(1);
        tblAddCandidate.Visible = true;
        txtAdd_RegDate.Text = DateTime.Today.ToShortDateString();


        foreach (ListItem _listItem in this.ddlAssTutAdd.Items)
        {
            _listItem.Attributes.Add("title", _listItem.Text);
        }


        ddlAssTutAdd.Attributes.Add("onmouseover", "this.title=this.options[this.selectedIndex].title");

        ddlAssTutAdd.SelectedIndex = -1; ddlCentresAdd.SelectedIndex = -1; rblAdd_Gender.SelectedIndex = -1;
        txtAdd_CandNo.Text = ""; txtAdd_DOB.Text = ""; txtAdd_Ethnicity.Text = ""; txtAdd_Forename.Text = "";
        txtAdd_Initials.Text = ""; txtAdd_LRS.Text = ""; txtAdd_Notes.Text = ""; txtAdd_RegDate.Text = "";
        txtAdd_Surname.Text = "";

        txtAdd_CandNo.Focus();

    }

下面的 aspx 代码)

                                    <asp:DropDownList ID="ddlAssTutAdd" TabIndex="9" runat="server" DataSourceID="SqlDataSource_TutAss"
                                    DataTextField="StaffName" DataValueField="StaffID" Width="300px"
                                    AppendDataBoundItems="true" >
                                    <asp:ListItem Value="0" Text="Please Select..." />    
                                </asp:DropDownList>

                                <asp:SqlDataSource ID="SqlDataSource_TutAss" runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:CenCoordConStr %>" 
                                    SelectCommand="SELECT Staff.StaffID + ' : ' + Staff.StaffFirstname + ' ' + Staff.StaffSurname AS StaffName, Staff.StaffID FROM Staff INNER JOIN Assessors ON Staff.StaffID = Assessors.StaffID">
                                </asp:SqlDataSource>

但是,它仅在您第二次单击“添加”按钮后才有效。单击它一次会加载带有“请选择...”的工具提示,但当将鼠标悬停在下拉列表中的任何项上时,它会显示此工具提示。选择某个项目后,工具提示将不再起作用。 如果您再次单击“添加”按钮,一切正常!

有人有想法吗?

谢谢, 内森

I have added a "tooltip" to my dropdownlist using the following codebehind:

        protected void btnAdd_Click(object sender, EventArgs e)
    {
        load_Buttons(1);
        tblAddCandidate.Visible = true;
        txtAdd_RegDate.Text = DateTime.Today.ToShortDateString();


        foreach (ListItem _listItem in this.ddlAssTutAdd.Items)
        {
            _listItem.Attributes.Add("title", _listItem.Text);
        }


        ddlAssTutAdd.Attributes.Add("onmouseover", "this.title=this.options[this.selectedIndex].title");

        ddlAssTutAdd.SelectedIndex = -1; ddlCentresAdd.SelectedIndex = -1; rblAdd_Gender.SelectedIndex = -1;
        txtAdd_CandNo.Text = ""; txtAdd_DOB.Text = ""; txtAdd_Ethnicity.Text = ""; txtAdd_Forename.Text = "";
        txtAdd_Initials.Text = ""; txtAdd_LRS.Text = ""; txtAdd_Notes.Text = ""; txtAdd_RegDate.Text = "";
        txtAdd_Surname.Text = "";

        txtAdd_CandNo.Focus();

    }

(aspx code below)

                                    <asp:DropDownList ID="ddlAssTutAdd" TabIndex="9" runat="server" DataSourceID="SqlDataSource_TutAss"
                                    DataTextField="StaffName" DataValueField="StaffID" Width="300px"
                                    AppendDataBoundItems="true" >
                                    <asp:ListItem Value="0" Text="Please Select..." />    
                                </asp:DropDownList>

                                <asp:SqlDataSource ID="SqlDataSource_TutAss" runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:CenCoordConStr %>" 
                                    SelectCommand="SELECT Staff.StaffID + ' : ' + Staff.StaffFirstname + ' ' + Staff.StaffSurname AS StaffName, Staff.StaffID FROM Staff INNER JOIN Assessors ON Staff.StaffID = Assessors.StaffID">
                                </asp:SqlDataSource>

However it only works once you click the "Add" button for the second time. Clicking it once loads the tooltip with "Please Select..." but it shows this tooltip when hovering over any item in the dropdown list. Once you select an item, the tooltip no longer functions.
If you click the "Add" button again it all works correctly!

Does anybody have an idea?

Thanks,
Nathan

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

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

发布评论

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

评论(2

纵情客 2024-10-05 17:42:11
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownList1.Items[0].Attributes.Add("Title", "Punjab Pollution Control Board");
            DropDownList1.Items[1].Attributes.Add("Title", "Hello");

        }
    }
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownList1.Items[0].Attributes.Add("Title", "Punjab Pollution Control Board");
            DropDownList1.Items[1].Attributes.Add("Title", "Hello");

        }
    }
因为看清所以看轻 2024-10-05 17:42:11

对不起Lee Sy En,我应该说我正在使用IE8。

我通过在代码隐藏中而不是在 aspx 代码中设置数据源来解决这个问题。我仍然想知道为什么它不能以这种方式工作,但如果有人能够阐明它,只是出于好奇!

Sorry Lee Sy En, I should have said that I am using IE8.

I got around the problem by setting the datasource in the codebehind rather than in the aspx code. I'd still like to know why it didn't work this way though if anyone can shed some light on it, just out of curiosity!

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