asp.net 下拉列表工具提示(标题)奇怪的行为
我使用以下代码隐藏在我的下拉列表中添加了一个“工具提示”:(
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对不起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!