zoukankan      html  css  js  c++  java
  • BUGReport:datagrid带模板列绑定空数据集出错的问题

    datagrid带模板列绑定空数据集出错的问题:GridView比DataGrid好的原因之一

    BUG描述:datagrid带模板列绑定空数据集时会出错,而同样的代码asp.net 2.0中的GridView不会出错(难到MS已经认识到这一点,所以datagrid也被2.0抛弃了,不过gridview继承自不同的基类,害我改oracle,sqlserver,access的三方万能分页控件好辛苦呀)

    Bug存在于 asp.net 1.1 asp.net 2.0

    测试工具:vs.net 2003,vs.net 2005,vs.net 2005 sp1,SQLserver


    测试过程:
    setp1:
    //无绑定列,采用自动生成
    WebForm1.aspx:
    <form id="Form1" method="post" runat="server">
     <asp:DataGrid ID=DataGrid1 runat=server>       
            </asp:DataGrid>
    </form>
    WebForm1.cs:
    private void Page_Load(object sender, System.EventArgs e)
      {
       SqlDataReader Reader2 = DBHelper("select 26 age, 'test' test where 1=0");
       DataGrid1.DataSource = Reader2;
       DataGrid1.DataBind();
       Reader2.Close(); 
      }

      SqlDataReader DBHelper(string sql)
      {
       SqlConnection conn = new SqlConnection("server=localhost;uid=sa;pwd=;database=Northwind");
       SqlCommand cmd = new SqlCommand(sql, conn);
       conn.Open();
       SqlDataReader Reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
       return Reader;
      }
    程序执法成功,DataGrid无显示

    setp2:
    //绑定列,采用自动生成
    WebForm1.aspx:
    <form id="Form1" method="post" runat="server">
      <asp:DataGrid ID=DataGrid1 runat=server>
             <Columns>
              <asp:TemplateColumn>
               <ItemTemplate>
                <asp:CheckBox ID=ck1 runat=server />
               </ItemTemplate>
              </asp:TemplateColumn>
             </Columns>
            </asp:DataGrid>

    </form>
    WebForm1.cs:
    代码不变

    程序执行失败,在做DataGrid1.DataBind()时提示
    Invalid attempt to Read when reader is closed.
    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.InvalidOperationException: Invalid attempt to Read when reader is closed.

    同样在asp.net 2.0里,采用带模板列的GridView(只是把GridView的ID也取名为DataGrid1),后台代码不变,执行成功。
    <asp:GridView ID=DataGrid1 runat=server>
            <Columns>
           <asp:TemplateField>
            <ItemTemplate>
               <asp:CheckBox ID=ck1 runat=server />
              </ItemTemplate>
           </asp:TemplateField>
         </Columns>
    </asp:GridView>



    后记:今天本想去http://www.mscommunity.com/communitywish/ 在线提交BUG的,结果居然发现打开是中华部落阁,不知是MS的这个网站倒闭了还是被恶意抢注了,或是埃塞的DNS解析有问题。以前提交过oracleclient连接的一个问题,在博客园的也写了一下。后来也找到了写这个模块的老外在网上的文章,确认当时写的时候没注意,还提供了一个hotfix。如果这个也算是bug的话,那就是第2个了。^_^0,不过现在非洲,基本什么也访问不了,博客园上不了,csdn上不去,只能写写sohu的blog了。

  • 相关阅读:
    【转】微服务架构模式简介
    大话微服务
    Howto: 在ArcGIS10中将地图文档(mxd文档)批量保存到之前版本
    在Google Maps中导出KML文件
    ASP.NET(c#) 日期选择控件的另一种实现方法
    asp.net中的时间日期选择控件
    JAVA实现Excel导入/导出【转】
    将Gridview中的数据出到excel或word中
    asp.net导出excel并弹出保存提示框
    在ASP.NET中将GridView数据导出到Word、Excel
  • 原文地址:https://www.cnblogs.com/tongzhenhua/p/642333.html
Copyright © 2011-2022 走看看