附上代码:
前台代码
<table width="100%" style="border-collapse: collapse" border="0" cellspacing="1"
cellpadding="3" align="center">
<tr>
<td colspan="4" align="center">
<asp:DataGrid ID="gvList" runat="server" AutoGenerateColumns="true">
</asp:DataGrid>
</td>
</tr>
</table>
后台绑定数据源
if (!this.IsPostBack)
{
if (Session["fields"] != null && Session["where"] != null)
{
ReadyData();
}
}
else
{
Response.Write("<script>window.history.back(-1);</script>");
}
private void ReadyData()
{
QueryParam qp = new QueryParam();
qp.ReturnFields = Session["fields"].ToString();
string strWhere = Session["where"].ToString();
qp.Where = strWhere;
int Reco = 0;
DataTable dv = BLL.BusinessDeel.sys_GetEmployeeInfoTable(qp, out Reco); gvList.DataSource = dv;
gvList.DataBind();
Session.Remove("fields");
Session.Remove("where"); }
//***********************************************************************************************
上面代码运行正常,但将前台DataGrid换成GridView就不行了
<table width="100%" style="border-collapse: collapse" border="0" cellspacing="1"
cellpadding="3" align="center">
<tr>
<td colspan="4" align="center">
<asp:GridView ID="gvList" runat="server" AutoGenerateColumns="true">
</asp:GridView>
</td>
</tr>
</table>
前台代码
<table width="100%" style="border-collapse: collapse" border="0" cellspacing="1"
cellpadding="3" align="center">
<tr>
<td colspan="4" align="center">
<asp:DataGrid ID="gvList" runat="server" AutoGenerateColumns="true">
</asp:DataGrid>
</td>
</tr>
</table>
后台绑定数据源
if (!this.IsPostBack)
{
if (Session["fields"] != null && Session["where"] != null)
{
ReadyData();
}
}
else
{
Response.Write("<script>window.history.back(-1);</script>");
}
private void ReadyData()
{
QueryParam qp = new QueryParam();
qp.ReturnFields = Session["fields"].ToString();
string strWhere = Session["where"].ToString();
qp.Where = strWhere;
int Reco = 0;
DataTable dv = BLL.BusinessDeel.sys_GetEmployeeInfoTable(qp, out Reco); gvList.DataSource = dv;
gvList.DataBind();
Session.Remove("fields");
Session.Remove("where"); }
//***********************************************************************************************
上面代码运行正常,但将前台DataGrid换成GridView就不行了
<table width="100%" style="border-collapse: collapse" border="0" cellspacing="1"
cellpadding="3" align="center">
<tr>
<td colspan="4" align="center">
<asp:GridView ID="gvList" runat="server" AutoGenerateColumns="true">
</asp:GridView>
</td>
</tr>
</table>
可以自己试一试随便从数据库读取数据查看效果,看是否如我所说一样
现在还不确定是否是微软的bug,希望大家测试下
这个问题遇到我都会想当然认为gridview自动生成列没问题,实际上遇到这个问题实在不知原因在哪里?
该不会是因为我的版本是盗版的吧?
他说:gridview即使设置autogeneratecolumns="true",后台绑定数据源也不可以自动生成列
除非先生成一个sqldatasource,然后赋给gridview数据源,呈现数据后,把sqldatasource再删除,保留gridview标签,后台绑定就可以了
三台win2003操作系统中使用GridView 的自动生成列无效,不能自动绑定显示数据库数据,而改成DataGrid就可以
xp中GridView 和datagrid 自动生成列可以自动绑定正常显示数据库表字段不知本人统计的数据基数是不是太小(总计4台机器) 不知是否可以得出GridView存在bug??