尝试将数据从LINQ绑定到SQL到Repeater时出错 [英] Error when trying to bind data from LINQ to SQL to Repeater

查看:71
本文介绍了尝试将数据从LINQ绑定到SQL到Repeater时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi:
I had this err
DataBinding: 'System.Char' does not contain a property with the name 'myProductName'.
How could I solve this problem please.




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace myWebApplication
{
    public partial class Repeater2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                showProducts();
            }
            else
            {
                showProducts();
            }
        }
        private void showProducts()
        {
            dbDataContext db = new dbDataContext();

            var stuff = from p in db.tblmyWebsites
                        select new
                        {
                            p.Id,
                            myProductName = p.productName,
                            p.tblprogrammingLanguage.programmingLanguage,
                            p.tblapplicationType.applicationType,
                            p.image,
                            myReview = p.review,
                            p.price
                        };
            Repeater1.DataSource = stuff.ToString();
            Repeater1.DataBind();


        }
    }
}







<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Repeater2.aspx.cs" Inherits="myWebApplication.Repeater2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
           <h3>
               <asp:Literal ID="Literal1" Text='<%# Eval("myProductName") %>' runat="server" Mode="Transform"></asp:Literal>
           </h3>
            <asp:BulletedList ID="BulletedList1" DataSource='<%# Eval("myReview") %>' DataTextField="review" runat="server">
            </asp:BulletedList>
        </ItemTemplate>
     </asp:Repeater>
    </div>
    </form>
</body>
</html>

推荐答案

更改此绑定格式

Change this binding format
Repeater1.DataSource = stuff.ToList();//Don't write ToString()
Repeater1.DataBind();


这篇关于尝试将数据从LINQ绑定到SQL到Repeater时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆