前台:
<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();