我尝试使用dropdownlist
和selectedvalue
绑定解决此问题。如果从SelectedValue
(dropdownlist
和club_ddl
)移除team_ddl
工作正常,但是如果将SelectedValue
属性添加到绑定DataSource
则返回错误“数据绑定Eval()
,XPath()
和Bind()
等方法只能在databound
控件的上下文中使用。
我该如何解决这个错误?
谢谢
<!DOCTYPE html>
<%@ Page Language="VB" %>
<html>
<head runat="server">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Untitled 1</title>
</head>
<body>
<form id="form1" runat="server">
<asp:AccessDataSource runat="server" id="result_db" DataFile="../App_Data/2016.mdb" DeleteCommand="DELETE FROM [result] WHERE [id] = ?" InsertCommand="INSERT INTO [result] ([class], [club], [team], [skor]) VALUES (?, ?, ?, ?)" SelectCommand="SELECT * FROM [result]" UpdateCommand="UPDATE [result] SET [class] = ?, [club] = ?, [team] = ?, [skor] = ? WHERE [id] = ?">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="class" Type="String" />
<asp:Parameter Name="club" Type="String" />
<asp:Parameter Name="team" Type="String" />
<asp:Parameter Name="skor" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="class" Type="String" />
<asp:Parameter Name="club" Type="String" />
<asp:Parameter Name="team" Type="String" />
<asp:Parameter Name="skor" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
</asp:AccessDataSource>
<asp:AccessDataSource runat="server" id="class_db" DataFile="../App_Data/2016.mdb" SelectCommand="SELECT [class] FROM [team] GROUP BY [class] ORDER BY [class]"></asp:AccessDataSource>
<asp:AccessDataSource runat="server" id="club_db" DataFile="../App_Data/2016.mdb" SelectCommand="SELECT [class], [club] FROM [result] WHERE ([class] = Α)">
<selectParameters>
<asp:ControlParameter ControlID="result_fv$class_ddl" Name="class" Type="String" />
</SelectParameters>
</asp:AccessDataSource>
<asp:AccessDataSource runat="server" id="team_db" DataFile="../App_Data/2016.mdb" SelectCommand="SELECT * FROM [team] WHERE (([class] = ?) AND ([club] = ?))">
<SelectParameters>
<asp:ControlParameter ControlID="result_fv$class_ddl" Name="class" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="result_fv$club_ddl" Name="club" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:AccessDataSource>
<asp:FormView runat="server" id="result_fv" DataKeyNames="id" DataSourceID="result_db" DefaultMode="Insert">
<InsertItemTemplate>
class:
<asp:DropDownList runat="server" id="class_ddl" DataSourceID="class_db" DataTextField="class" DataValueField="class" AutoPostBack="True" SelectedValue='<%# Bind("class") %>'></asp:DropDownList>
<br />
club:
<asp:DropDownList runat="server" id="club_ddl" DataSourceID="club_db" DataTextField="club" DataValueField="club" AutoPostBack="True" SelectedValue='<%# Bind("club") %>'></asp:DropDownList>
<br />
team:
<asp:DropDownList runat="server" id="team_ddl" DataSourceID="team_db" DataTextField="team" DataValueField="team" SelectedValue='<%# Bind("team") %>'></asp:DropDownList>
<br />
skor:
<asp:TextBox id="skorTextBox" runat="server" Text='<%# Bind("skor") %>' />
<br />
<asp:LinkButton id="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
<asp:LinkButton id="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
</asp:FormView>
</form>
</body>
</html>