Từ 1 tới 2 trên tổng số 2 kết quả

Đề tài: báo lỗi khi lấy dữ liệu lên gridview

  1. #1
    Ngày gia nhập
    09 2010
    Bài viết
    18

    Mặc định báo lỗi khi lấy dữ liệu lên gridview

    Chào các bạn,
    Tình hình là mình bị lỗi
    A field or property with the name '' was not found on the selected data source
    Đây Giao diện gridview của mình
    Code:
       <asp:GridView ID="grvNews" runat="server" AutoGenerateColumns="False" Width="360px">                    
                        <Columns>
                            <asp:BoundField HeaderText="ID" DataField="id" />
                            <asp:BoundField HeaderText="Title" DataField="title" SortExpression="title" />
                            <asp:BoundField HeaderText="Content VN" DataField="contentVN" SortExpression="contentVN" />
                            <asp:BoundField HeaderText="Content Eng" DataField="contentENG" SortExpression="contentENG" />
                            <asp:BoundField HeaderText="Date" DataField="newsDate" SortExpression="newsDate"/>
                            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowHeader="True" />
                        </Columns>
                        <EditRowStyle BackColor="#F0FFF0" />
                        <FooterStyle BackColor="#F0FFF0" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#FF0000" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#F0FFF0" ForeColor="White" HorizontalAlign="Center" />
                        <RowStyle BackColor="#F0FFF0" />
                    </asp:GridView>
    Code:
            public string id 
            {
                get { return _id; }
                set {_id=value ;} 
            }
            public string title
            {
                get { return _title; }
                set { _title = value; }
            }
            public string content_vn
            {
                get { return _content_vn; }
                set { _content_vn = value; }
            }
            public string content_en
            {
                get { return _content_en; }
                set { _content_en = value; }
            }
            public string news_date
            {
                get { return _news_date; }
                set { _news_date = value; }
            }
    Code:
     public List<news_admin> News_GetByAll()
            {
                List<news_admin> list = new List<news_admin>();
                using (SqlCommand cmd = new SqlCommand("sp_news_GetByAll", openConnect()))
                {
                    news_admin obj = new news_admin();
                    cmd.CommandType = CommandType.StoredProcedure;
    
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            list.Add(NewsIDataReader(dr));
                        }
                    }
                    dr.Close();
                    obj = null;
                }
                return list;
            }
    Mình code theo mô hình 3 tier
    Nó báo lỗi ở gridview không nhận được cột contentVN, khi mình xóa 3 cột cuối đi thì nó nhận 2 cột ID và Title nhưng lại hiển thị Title vào cột ID @@

  2. #2
    Ngày gia nhập
    08 2014
    Nơi ở
    USA
    Bài viết
    623

    Bạn phải viết là: content_vn thay vì ContentVN, tại trong properties là content_vn
    VNFox là ai? www.vnfox.com
    Cafe cùng VNFox @ fb.me/vnfoxcafe

Quyền hạn của bạn

  • Bạn không thể gửi đề tài mới
  • Bạn không thể gửi bài trả lời
  • Bạn không thể gửi các đính kèm
  • Bạn không thể chỉnh sửa bài viết của bạn