C#:DataBinding:“System.Data.DataRowView”不包含名为“id”的属性。

在使用sqldatasource、GridView控件联用时,如果报上述错误,就说明,GridView中的数据源SqlDatasource主键字段属性没有规定,应在GridView属性设置中加入DataKeyNames=“id”。
Code
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                                                                                        AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid"
                                                                                        BorderWidth="1px" CellPadding="3"    DataKeyNames="id"    DataSourceID="SqlDataSource1" EmptyDataText="没有可显示的数据记录。"
                                                                                        ForeColor="Black" GridLines="Vertical" Width="100%" PageSize="5">
                                                                                         < FooterStyle BackColor ="#CCCCCC" />
                                                                                         < Columns >
                                                                                                 < asp:CommandField ShowEditButton ="True" />
                                                                                                 < asp:CommandField ShowDeleteButton ="True" />
                                                                                                 < asp:BoundField DataField ="zq" HeaderText ="长贷期限" SortExpression ="zq" />
                                                                                                 < asp:BoundField DataField ="cdje" HeaderText ="长贷金额" SortExpression ="cdje" />
                                                                                         </Columns>
                                                                                         < PagerStyle BackColor ="#999999" ForeColor ="Black" HorizontalAlign ="Center" />
                                                                                         < SelectedRowStyle BackColor ="#000099" Font-Bold ="True" ForeColor ="White" />
                                                                                         < HeaderStyle BackColor ="Black" Font-Bold ="True" ForeColor ="White" />
                                                                                         < AlternatingRowStyle BackColor ="#CCCCCC" />
                                                                                 </asp:GridView>

本文出自 “叶子文文” 博客,转载请与作者联系!

你可能感兴趣的:(C#,休闲,id属性,DataRowView,DateBinding)