当前位置: 代码迷 >> ASP.NET >> “DataBinder.Eval:“System.Data.DataRowView”不包含名称为的属性”异常~请帮忙改改代码
  详细解决方案

“DataBinder.Eval:“System.Data.DataRowView”不包含名称为的属性”异常~请帮忙改改代码

热度:9523   发布时间:2013-02-26 00:00:00.0
“DataBinder.Eval:“System.Data.DataRowView”不包含名称为的属性”错误~~~!!!请帮忙改改代码
前台:
<asp:datagrid   id= "DataGrid1 "   runat= "server "   DataKeyField= "zsxm.id "   >
<Columns>
<asp:HyperLinkColumn   DataNavigateUrlField= "zsxm.id "   DataNavigateUrlFormatString= "xmxs.aspx?id={0} "   DataTextField= "mc "> </asp:HyperLinkColumn>
<asp:HyperLink   runat= "server "   Text= ' <%#   DataBinder.Eval(Container,   "DataItem.hyuser ")   %> '   NavigateUrl= ' <%#   string.Format( "hyxs.aspx?id={0} ",   DataBinder.Eval(Container,   "DataItem.hy.id "))     %> '   Target= "_blank "> </asp:HyperLink>
...
</asp:datagrid>

后台:
string   sql   =   "SELECT   zsxm.mc,   zsxm.id,   zsxm.sj,   hy.id,   hy.hyuser   FROM   zsxm   INNER   JOIN   hy   ON   zsxm.hyid   =   hy.id   ORDER   BY   zsxm.id   DESC ";    
DataView   zhuantiview   =   getdataview(sql,   "zhuanti1 ");  
DataGrid1.DataSource   =   zhuantiview;
DataGrid1.DataBind();  


------解决方案--------------------------------------------------------
DataItem.id你两个id字段最好指定个别名。如 zsxml.id as id1
------解决方案--------------------------------------------------------
前台:
<asp:datagrid id= "DataGrid1 " runat= "server " DataKeyField= "zsxmid " >
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField= "zsxmid " DataNavigateUrlFormatString= "xmxs.aspx?id={0} " DataTextField= "mc "> </asp:HyperLinkColumn>
<asp:HyperLink runat= "server " Text= ' <%# DataBinder.Eval(Container, "DataItem.hyuser ") %> ' NavigateUrl= ' <%# string.Format( "hyxs.aspx?id={0} ", DataBinder.Eval(Container, "DataItem.hy.id ")) %> ' Target= "_blank "> </asp:HyperLink>
...
</asp:datagrid>

后台:
string sql = "SELECT zsxm.mc, zsxm.id as zsxmid, zsxm.sj, hy.id as hyid, hy.hyuser FROM zsxm INNER JOIN hy ON zsxm.hyid = hy.id ORDER BY zsxm.id DESC ";
DataView zhuantiview = getdataview(sql, "zhuanti1 ");
DataGrid1.DataSource = zhuantiview;
DataGrid1.DataBind();
  相关解决方案