首页新闻找找看学习计划

asp.net gridview 问题

0
悬赏园豆:15 [待解决问题]

<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();
}
}
}

杨顺的主页 杨顺 | 初学一级 | 园豆:187
提问于:2015-05-20 22:42
< >
分享
所有回答(3)
0

数据表或者绑定的SQL语句中有BookID这个字段吗?

火悬崖 | 园豆:434 (菜鸟二级) | 2015-05-21 08:23
0

 你这里面 BookManager.SelectAllBooks(); 包含BookID字段吗?

可以debug一下

chengdu.jack.li | 园豆:274 (菜鸟二级) | 2015-05-21 15:19
0

答案已经很明朗了,大哥,你能涨点心吗?

| 园豆:750 (小虾三级) | 2015-05-22 17:32
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册