我正在开发Asp Web应用程序我有div,如图所示div将在onmouseover上打开。
我想在按钮的onmouseover事件上加载数据。我无法找到任何代码从鼠标上的数据库加载数据有没有办法解决它?
我尝试了这段代码,但它显示了“<%#Container.DataItem(”CustomerName“)%>” “非可调用成员'System.Web.UI.WebControls.RepeaterItem.DataItem'不能像方法一样使用。”
<head runat="server">
<title></title>
<script>
$('#Button1').on('mouseover',
function{
SqlConnection dbconn= New SqlConnection("Provider=System.Data.SqlClient;Data Source=localhost;Initial Catalog=ElectricalStrings_beta;Trusted_Connection = True;")
dbconn.Open()
sql="SELECT * FROM Feedback";
SqlCommand dbcomm = New SqlCommand(sql,dbconn)
SqlDataReader dbread=dbcomm.ExecuteReader()
customers.DataSource=dbread
customers.DataBind()
dbread.Close()
dbconn.Close()
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" />
<div id ="menu">
<asp:Repeater ID="customers" runat="server">
<HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>Companyname</th>
<th>Contactname</th>
<th>Address</th>
<th>City</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Container.DataItem("CustomerName")%></td>
<td><%#Container.DataItem("CustomerMobileNo")%></td>
<td><%#Container.DataItem("Feedback")%></td>
<td><%#Container.DataItem("Status")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>