<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" PageSize="15" AllowPaging="True" CellPadding="1" DataKeyNames="BookID" ForeColor="#333333">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 110px; height: 19px; text-align: center;">
<%# Eval("BookID")%>
</td>
<td style="width: 110px; height: 19px; text-align: center;">
<%# Eval("BookName")%>
</td>
<td style="width: 110px; height: 19px; text-align: center;">
<%# Eval("ManID")%>
</td>
<td style="width: 80px; height: 19px; text-align: center;">
<asp:LinkButton ID="lblupdate" runat="server" PostBackUrl='<%# "BookDetail.aspx?BookID="+ Eval("BookID") %>'>详细</asp:LinkButton></td>
</tr>
</table>
</ItemTemplate>
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 110px; height: 19px; text-align: center">
图书编号</td>
<td style="width: 110px; height: 19px; text-align: center">
图书名</td>
<td style="width: 110px; height: 19px; text-align: center">
管理编号</td>
<td style="width: 80px; height: 19px; text-align: center">
详细
</td>
</tr>
</table>
</HeaderTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
报错如下
DataBinding:“System.Data.DataRowView”不包含名为“BookID”的属性。]????
这是后台代码
public partial class BookSearch : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
//验证Session对象,判断用户是否登陆
if (Session["UserID"].ToString() == "" || Session["UserID"].ToString() == null || Session["Level"].ToString() != "2")
{
Response.Redirect("Login.aspx");
return;
}
}
//Session对象未初始化,跳转登陆页面。
catch (NullReferenceException)
{
Response.Redirect("Login.aspx");
}
lblUserName.Text = Session["UserName"].ToString();
if (!IsPostBack)
{
GridView1.DataSource = BookManager.SelectAllBooks();
GridView1.DataBind();
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
if (txtkey.Text.Trim() == "")
{
GridView1.DataSource = BookManager.SelectAllBooks();
GridView1.DataBind();
}
else
{
GridView1.DataSource = BookManager.SelectBookByType(DropDownList1.SelectedValue, txtkey.Text);
GridView1.DataBind();
}
}
}
数据表或者绑定的SQL语句中有BookID这个字段吗?
你这里面 BookManager.SelectAllBooks(); 包含BookID字段吗?
可以debug一下
答案已经很明朗了,大哥,你能涨点心吗?