foreach (DataGridItem dgi in this.GridView1.items)
编译器错误信息: CS0117: “System.Web.UI.WebControls.GridView”并不包含“items”的定义

解决方案 »

  1.   

    在VS05里GridView没有Item属性,只有Rows和Columns属性了,lz的应该是Rows吧。
      

  2.   

    foreach   (DataGridRow   dgi   in   this.GridView1.Rows) 
      

  3.   

    foreach       (DataGridRow       dgi       in       this.GridView1.Rows) 
    那这句是什么意思呢
      

  4.   

    GridView.Rows 属性注意:此属性在 .NET Framework 2.0 版中是新增的。获取表示 GridView 控件中数据行的 GridViewRow 对象的集合。 命名空间:System.Web.UI.WebControls
    程序集:System.Web(在 system.web.dll 中)属性值
    一个 GridViewRowCollection,包含 GridView 控件中的所有数据行。Rows 属性(集合)用来存储 GridView 控件中的数据行。GridView 控件自动填充 Rows 集合,方法是为数据源中的每条记录创建一个 GridViewRow 对象,然后将每个对象添加到该集合。此属性通常用于访问控件中的特定行或者循环访问整个行集合。注意 
    只有其 RowType 属性设置为 DataControlRowType.DataRow 的行才会存储在 Rows 集合中。该集合中不包括表示标题行、脚注行和页导航行的 GridViewRow 对象。示例
    下面的代码示例演示如何使用 Rows 集合访问 GridView 控件中正在编辑的行。在行被更新之后,会显示一条消息指示更新成功。
    <%@ Page language="C#" %><script runat="server">
      
      void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
      {
        
        // Clear the message label when the user enters edit mode.
        if (e.CommandName == "Edit")
        {
          Message.Text = "";
        }
        
      }  void CustomersGridView_RowUpdated(Object sender, GridViewUpdatedEventArgs e)
        {
       
            // The update operation was successful. Retrieve the row being edited.
            int index = CustomersGridView.EditIndex;
            GridViewRow row = CustomersGridView.Rows[index];
            
            // Notify the user that the update was successful.
            Message.Text = "Updated record " + row.Cells[1].Text + ".";
        
        }  void CustomersGridView_RowCancelingEdit(Object sender, GridViewCancelEditEventArgs e)
        {
       
            // The update operation was canceled. Display the appropriate message.
            Message.Text = "Update operation canceled.";
        
        }</script><html>
      <body>
        <form runat="server">
            
          <h3>GridView Rows Example</h3>
                
          <asp:label id="Message"
            forecolor="Red"
            runat="server"/>
                    
          <br/>    
                
          <!-- The GridView control automatically sets the columns     -->
          <!-- specified in the datakeynames property as read-only.    -->
          <!-- No input controls are rendered for these columns in     -->
          <!-- edit mode.                                              -->
          <asp:gridview id="CustomersGridView"
            allowpaging="true" 
            datasourceid="CustomersSqlDataSource" 
            autogeneratecolumns="true"
            autogenerateeditbutton="true"
            datakeynames="CustomerID"
            onrowcommand="CustomersGridView_RowCommand"
            onrowupdated="CustomersGridView_RowUpdated"
            onrowcancelingedit="CustomersGridView_RowCancelingEdit"  
            runat="server">
          </asp:gridview>
                
          <!-- This example uses Microsoft SQL Server and connects  -->
          <!-- to the Northwind sample database. Use an ASP.NET     -->
          <!-- expression to retrieve the connection string value   -->
          <!-- from the Web.config file.                            -->
          <asp:sqldatasource id="CustomersSqlDataSource"  
            selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
            updatecommand="Update Customers SET CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country WHERE (CustomerID = @CustomerID)"
            deletecommand="Delete from Customers where CustomerID = @CustomerID"
            connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
            runat="server">
          </asp:sqldatasource>
                
        </form>
      </body>
    </html>