'System.Data.DataRowView'没有包含此名称'ID'的属性.

提示信息

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ID'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ID'.

Source Error: 


Line 19:                 <asp:TemplateField HeaderStyle-CssClass="ID" HeaderText="ID" >
Line 20:                     <ItemTemplate>
Line 21:                         <div><a href='photo.aspx?id=<%#Eval("ID") %>'><%#Eval("ID") %></a></div>
Line 22:                     </ItemTemplate>
Line 23: 

Source File: d:\Files\Website\Akon\Akon\Akon\search.aspx    Line: 21 

Stack Trace: 


[HttpException (0x80004005): DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ID'.]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +9558245
   System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts) +104
   System.Web.UI.DataBinder.Eval(Object container, String expression) +93
   System.Web.UI.TemplateControl.Eval(String expression) +43
   ASP.search_aspx.__DataBind__control11(Object sender, EventArgs e) in d:\Files\Website\Akon\Akon\Akon\search.aspx:21
   System.Web.UI.Control.OnDataBinding(EventArgs e) +92
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +85
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +187
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +94
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +187
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +94
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +167
   System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +3724
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +67
   System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +123
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
   System.Web.UI.WebControls.GridView.DataBind() +4
   Akon.search.Page_Load(Object sender, EventArgs e) in d:\Files\Website\Akon\Akon\Akon\search.aspx.cs:22
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

源代码:

 <div class="results">
        <asp:GridView ID="results" runat="server" AutoGenerateColumns="False" GridLines="None" BorderColor="White" HorizontalAlign="Center" >
            <Columns>
                <asp:TemplateField HeaderStyle-CssClass="ID" HeaderText="ID" >
                    <ItemTemplate>
                        <div><a href='photo.aspx?id=<%#Eval("ID") %>'><%#Eval("ID") %></a></div>
                    </ItemTemplate>

                    <ControlStyle></ControlStyle>

                    <HeaderStyle />
                </asp:TemplateField>
                <asp:TemplateField HeaderStyle-CssClass="Name" HeaderText="Name">
                    <ItemTemplate>
                        <div><a href='photo.aspx?id=<%#Eval("ID") %>'><%#Eval("Name") %></a></div>
                    </ItemTemplate>

                    <ControlStyle></ControlStyle>

                    <HeaderStyle/>
                </asp:TemplateField>
                <asp:TemplateField HeaderStyle-CssClass="Brif" HeaderText="Brif">
                    <ItemTemplate>
                        <div><a href='photo.aspx?id=<%#Eval("ID") %>'><%#Eval("Brif") %></a></div>
                    </ItemTemplate>

                    <ControlStyle></ControlStyle>

                    <HeaderStyle/>
                </asp:TemplateField>
                <asp:TemplateField HeaderStyle-CssClass="Info" HeaderText="Info">
                    <ItemTemplate>
                        <div><a href='photo.aspx?id=<%#Eval("ID") %>'><%#Eval("Info") %></a></div>
                    </ItemTemplate>

                    <ControlStyle></ControlStyle>

                    <HeaderStyle/>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>

3个回答

绑定的数据没有id这个字段

Movart
Movart 能详细说下吗?多谢!
5 年多之前 回复

要注意大小写,以及你的绑定表达式是否一致。

Movart
Movart 嗯,我再检查一下
5 年多之前 回复

看你绑定的数据源,有哪些字段

feiyun0112
feiyun0112 回复Movart: 看看你绑定的sql
5 年多之前 回复
Movart
Movart 数据库里有ID,Name,Brif,Info
5 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问