我收到此錯誤:錯誤的SqlDataSource數據綁定到GridView的
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
我試圖綁定SqlDataSource
的結果爲GridView
。
這是代碼:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="grid_getbranch" Height="111px" Width="91px">
<Columns>
<asp:TemplateField HeaderText="branch" SortExpression="branch">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("branch") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("branch") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="name" SortExpression="name">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="grid_getbranch" runat="server"
ConnectionString="<%$ ConnectionStrings:svpolyConnectionString %>"
SelectCommand="SELECT branch.branch, course.name FROM branch INNER JOIN course ON branch.c_id = course.id WHERE (branch.c_id = @c_id)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList2" Name="c_id"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
確保沒有任何其他相關標記,可能是問題的根源? – 2012-02-16 20:23:30
消息很明確,錯誤的來源並非來自您所顯示的標記,您可以在控件或服務器端代碼中找到所陳述的方法。 – Mubarek 2012-02-16 20:31:24