DataView控件绑定错误
前台代码:
<asp:GridView ID="GridView1" runat="server" Width="600px" AutoGenerateColumns="False" CellPadding="2" DataKeyNames="wyx_id" EnableViewState="False" AllowPaging="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataSourceID="AccessDataSource1">
<Columns>
<asp:BoundField DataField="wyx_id" HeaderText="序号" />
<asp:BoundField HeaderText="分类" />
<asp:TemplateField HeaderText="标题">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("wyx_title") %>' NavigateUrl='<%# "admin_edit.aspx?id="+Eval("id") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="wyx_date" HeaderText="日期" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
<PagerSettings FirstPageText="首页" LastPageText="尾页" Mode="NextPreviousFirstLast"
NextPageText="下一页" PreviousPageText="上一页" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/data/wyx.mdb"
SelectCommand="SELECT [wyx_id], [wyx_class], [wyx_title], [wyx_date] FROM [wyx_text]">
</asp:AccessDataSource>
后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class admin_admin_text : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet ds = Socut.Data.ExecuteDataSet("SELECT * FROM wyx_text ORDER BY wyx_id DESC");//实例化DataSet
GridView1.DataSource = ds; //设置数据源
GridView1.DataBind(); //绑定数据
}
}