从Collection为datarow赋值

时间:2016-01-21 12:44:17

标签: c#

我有一个WCF服务,它根据下面给出的调用方法返回一个集合。但问题是在将这些值分配给datarow时,它不显示数据而是显示数据" ServiceReference1.CustomerDetails" (指集合本身)

 ServiceReference1.transactionProcessingSystemClient obj = new transactionProcessingSystemClient();

        Label1.Text = "Account Statement for " + Session["account"].ToString();
        IList<CustomerDetails> objAccountDetails = new List<CustomerDetails>();
        String id = Session["account"].ToString();
        objAccountDetails = obj.GetCustomerTransactionDetails(id);

        DataTable dt = new DataTable();
        DataRow dr = null;
        dt.Columns.Add(new DataColumn("No.", typeof(string)));
        dt.Columns.Add(new DataColumn("Amount", typeof(string)));
        dt.Columns.Add(new DataColumn("Transaction Type", typeof(string)));
        dt.Columns.Add(new DataColumn("Date", typeof(string)));
        for (int index = 0; index < objAccountDetails.Count; index++)
        {
            dr = dt.NewRow();
            int iRowNo = index + 1;
            dr["No."] = iRowNo;
            dr["Amount"] = objAccountDetails[index];
            dr["Transaction Type"] = objAccountDetails[index];
            dr["Date"] = objAccountDetails[index];
            dt.Rows.Add(dr);                                            
        }

        GridView1.DataSource = dt;
        GridView1.DataBind();

为了您的信息,我手动执行此操作,因为我只想显示集合中的某些数据。当我分配&#34; objAccountDetails&#34;到gridView它工作正常。

任何评论或想法请...

0 个答案:

没有答案