前台代码
...
<asp:GridView ID="gvdSearchMessageLog" runat="server" 
                     AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" 
                     GridLines="None" Width="100%">
                     <RowStyle BackColor="#EFF3FB" />
                     <Columns>
                         <asp:BoundField DataField="id" HeaderText="id" Visible="False" />
                         <asp:BoundField DataField="productname" HeaderText="商品名称" />
                         <asp:BoundField DataField="contents" HeaderText="留言内容" />
                         <asp:BoundField DataField="usersname" HeaderText="留言人" />
                         <asp:BoundField DataField="mtime" HeaderText="留言时间" />
                         <asp:TemplateField HeaderText="操作">
                             <EditItemTemplate>
                                 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                             </EditItemTemplate>
                             <ItemTemplate>
                                 <asp:Label ID="Label1" runat="server"></asp:Label>
                             </ItemTemplate>
                         </asp:TemplateField>
                     </Columns>
                     <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                     <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                     <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                     <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                     <EditRowStyle BackColor="#2461BF" />
                     <AlternatingRowStyle BackColor="White" />
</asp:GridView>后台代码     protected void gvdSearchMessageLog_Bind()
    {
        gvdSearchMessageLog.DataSource = GetEvaluateInfo.GetMessage();
        gvdSearchMessageLog.DataBind();
    }//得到数据.    private const string Sql_Evaluate_Select = "select a.id,b.productname,contents,usersname,mtime from evaluate a,product b,users c where a.productid=b.id and a.userid=c.id";    public List<Model.Back_Evaluate> GetMessage()
   {
     List<Model.Back_Evaluate> evaluateinfo = new List<Model.Back_Evaluate>();
     using (SqlDataReader rdr = SQLHelper.ExecuteReader(SQLHelper.ConnectionStringLocalTransaction, CommandType.Text, Sql_Evaluate_Select, null))
            {
                while (rdr.Read())
                {
                    Model.Back_Evaluate GetEvalInfo = new Model.Back_Evaluate(rdr.GetInt32(0),rdr.GetString(1),rdr.GetString(2),rdr.GetString(3),rdr.GetDateTime(4));
                    evaluateinfo.Add(GetEvalInfo);
                }
            }
            return evaluateinfo;
        }我是新手,取值是成功的..就是绑定GRIDVIEW时,,就是出错...字段名我都是复制的...请高手看看

解决方案 »

  1.   

    那就看看你Back_Evaluate实体类里面的属性是否写正确了。
      

  2.   

    实体类
    public class Back_Evaluate
        {
            private int id;        public int Id
            {
                get { return id; }
                set { id = value; }
            }        private string productname;        public string Productname
            {
                get { return productname; }
                set { productname = value; }
            }        private string contents;        public string Contents
            {
                get { return contents; }
                set { contents = value; }
            }        private string usersname;        public string Usersname
            {
                get { return usersname; }
                set { usersname = value; }
            }        private DateTime mtime;        public DateTime Mtime
            {
                get { return mtime; }
                set { mtime = value; }
            }        public Back_Evaluate() { }        public Back_Evaluate(int id, string productname, string contents, string usersname, DateTime mtime)
            {
                this.id = id;
                this.productname = productname;
                this.contents = contents;
                this.usersname = usersname;
                this.mtime = mtime;
            }
        }
    数据表
    CREATE TABLE [dbo].[evaluate](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [productid] [int] NULL,
    [score] [int] NULL,
    [contents] [varchar](200) NULL,
    [mtime] [datetime] NULL,
    [userid] [int] NULL,
    [Reply] [varchar](200) NULL,CREATE TABLE [dbo].[users](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [usersname] [varchar](30) NULL,
    [password] [varchar](20) NULL,
    [keeppwd] [varchar](30) NULL,
    [regiter] [datetime] NULL,
    [lastlogin] [datetime] NULL,
    [email] [varchar](30) NULL,
    [stateuing] [int] NULL,
    [points] [int] NULL,
    [VIP] [int] NULL,
    [roles] [varchar](10) NULL,
    [question] [varchar](30) NULL,
    [result] [varchar](30) NULL,
    [uptime] [datetime] NULL,
    [outtime] [datetime] NULL,
    [addreess] [varchar](50) NULL,
    [QQ] [varchar](30) NULL,
    [MSN] [varchar](30) NULL,
    [Mobile] [varchar](30) NULL,
    [TEl] [varchar](30) NULL,CREATE TABLE [dbo].[product](
    [id] [int] NOT NULL,
    [pid] [int] NULL,
    [productname] [varchar](30) NULL,
    [entryword] [varchar](2) NULL,
    [productnumber] [varchar](50) NULL,
    [images] [varchar](100) NULL,
    [price] [decimal](8, 2) NULL,
    [myprice] [decimal](8, 2) NULL,
    [VIPprice] [decimal](8, 2) NULL,
    [groupprice] [decimal](8, 2) NULL,
    [groups] [int] NULL,
    [least] [int] NULL,
    [look] [int] NULL,
    [ettime] [varchar](50) NULL,
    [weight] [varchar](20) NULL,
    [stockpile] [int] NULL,
    [re] [varchar](200) NULL,
    [exchange] [int] NULL,
    [point] [int] NULL,
    [stateuing] [int] NULL,
    [new] [int] NULL,
    [score] [int] NULL,
    [level] [int] NULL,
      

  3.   

    你到数据库里单独执行一下
    select a.id,b.productname,contents,usersname,mtime from evaluate a,product b,users c where a.productid=b.id and a.userid=c.id
    看看是否有数据。