ds=service1.SelRetds2("gzwj_view","",sortfield.ToString());
DataColumn sequence=new DataColumn();
sequence.DataType=System.Type.GetType("System.Int32");
sequence.AllowDBNull=false;
sequence.Caption="sortnum";
sequence.ColumnName="count";
ds.Tables[0].Columns.Add(sequence);
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
ds.Tables[0].Rows[i]["count"]=i+1;
}
DataView source=new DataView();
source=ds.Tables[0].DefaultView;
DataGrid1.DataSource=source;
DataGrid1.DataKeyField="BH";
DataGrid1.CurrentPageIndex=page_no;
DataGrid1.DataBind();

解决方案 »

  1.   

    公供参考<%@ Page language="c#" debug="True"%>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %><script language="c#" runat="server">Double dblRunningTotal = 0;void Page_Load(Object sender,EventArgs e)
    {
        if (!Page.IsPostBack)
            MyDataBind(); 
    }void MyDataBind()
    {
        OleDbConnection objConnection;
        OleDbCommand objCommand;
        OleDbDataReader objDataReader;
        String strSQLQuery;    objConnection = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=\\\\premfsx\\sites\\premiumx\\xxxxxxx\\database\\northwind.mdb");
        strSQLQuery = "Select ProductID,ProductName,UnitPrice,UnitsInStock FROM Products ORDER BY ProductID";    objCommand = new OleDbCommand(strSQLQuery, objConnection);
        objConnection.Open();    // bind data to grid
        MyDataGrid.DataSource = objCommand.ExecuteReader(CommandBehavior.CloseConnection);
        MyDataGrid.DataBind();    // close db
        objConnection.Close();}
    void MyDataGrid_ItemDataBound(Object sender, DataGridItemEventArgs e)
    {      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
          {
              dblRunningTotal += (Double.Parse(e.Item.Cells[2].Text) * Double.Parse(e.Item.Cells[3].Text));
              return;
          }  
          if (e.Item.ItemType == ListItemType.Footer )
          {
            e.Item.Cells[2].Text="Total(Unit Price * Units in Stock)";
            e.Item.Cells[3].Text = String.Format("{0:c}", dblRunningTotal);
          }
    }</script>
    <html>
    <body><h3><font face="Verdana">Total in DataGrid footer</font> 
    <span runat="server" id="MySpan"/></h3><form runat="server">
    <ASP:DataGrid id="MyDataGrid" runat="server"
       OnItemDataBound="MyDataGrid_ItemDataBound" 
       ShowFooter="True">
    </ASP:DataGrid></form>
        
     </body>
    </html>
      

  2.   

    public void BindGrid()
    {
        DataSet ds = CreateDataSet();
        DataView dv = ds.Tables[0].DefaultView;    int i = 1;
        foreach(DataRowView drwv in dv)
        {
           drwv["RowID"] = i;
    i += 1;
        }    dgList.DataSource = dv; 
        dgList.DataBind();
    }
      

  3.   

    ds.Tables[0].Compute("sum(列名)","条件");条件可以这样写:
    排序的列名>=DataGrid的最后一行的值(升序)
    排序的列名<=DataGrid的最后一行的值(降徐)参见:ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfSystemDataDataTableClassComputeTopic.htmms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfsystemdatadatacolumnclassexpressiontopic.htm