0

我正在更新一个旧程序,它从不同的表(使用存储过程)收集信息并将它们显示在 ASPxGridView 上。我又添加了三列并尝试将它们绑定到 GridView。但是,我收到“未找到字段/属性”错误,无法继续。

起初,我以为没有检索到数据,但调试显示我用来填充 ASPxGridView 的 List 对象确实包含我想要添加的数据。

protected void search_Click(object sender, EventArgs e)
{
   CommentsDataSource.SelectParameters.Clear();
   CommentsDataSource.SelectMethod = "SelectCommentsByProject";
   CommentsDataSource.SelectParameters.Add("pProjectId", System.Data.DbType.String, searchStringTextBox.Text.Trim());
   CommentsDataSource.Databind();
}

搜索还有其他几个选项,但我主要关心的是在处理其余部分之前至少有一个工作。

private List<Comment> SelectCommentsByProject(string pSearchString)
{
   List<Comments> comments = null;

   if(!string.IsNullOrEmpty(pSearchString))
   {
      System.Data.EntityClient.EntityConnection ecnxn = (System.Data.EntityClient.EntityConnection)esmEntityManager.Connection;
      System.Data.SqlClient.SqlConnection cnxn = (System.Data.SqlClient.SqlConnection)ecnxn.StoreConnection;

      using (cnxn)
      {
          cnxn.Open();
          SqlCommand cmd = new SqlCommand();
          cmd = new SqlCommand("usp_esm_comment_getByProjectID", cnxn);
          cmd.Parameters.Add(new SqlParameter("@ProjectID", pSearchString));

          try
          {
              cmd.CommandType = System.Data.CommandType.StoredProcedure;

              SqlDataAdapter da = new SqlDataAdapter();
              da.SelectCommand = cmd;

              System.Data.DataSet ds = new System.Data.DataSet();
              da.Fill(ds);

              for (int i = 0; i < ds.Tables.Count; i++)
              {
                    if (ds.Tables[i] != null && ds.Tables[i].Rows.Count > 0)
                    {
                          comments = new List<Comment>();
                          foreach (System.Data.DataRow row in ds.Tables[i].Rows)
                          {
                               Comment comment = new Comment();
                               comment.CommentID = (int)row["CommentId"];
                               comment.ComplianceID = (Guid)row["ComplianceID"];
                               comment.CommentText = (row["Comment"] is DBNull) ? null : row["Comment"].ToString();
                               comment.CreatedBy = (row["CreatedBy"] is DBNull) ? null : row["CreatedBy"].ToString();
                               comment.CreatedOn = Convert.ToDateTime((row["CreatedOn"] is DBNull) ? null : row["CreatedOn"].ToString());
                                    comment.LastModifiedBy = (row["LastModifiedBy"] is DBNull) ? null : row["LastModifiedBy"].ToString();
                               comment.LastModifiedOn = Convert.ToDateTime((row["LastModifiedOn"] is DBNull) ? null : row["LastModifiedOn"].ToString());
                               comment.RequestID = (row["RequestID"] is DBNull) ? null : row["RequestID"].ToString();
                               comment.TypeOfService = (row["TypeOfService"] is DBNull) ? null : row["TypeOfService"].ToString();
                               comment.ProjectID = (row["ProjectID"] is DBNull) ? null : row["ProjectID"].ToString();
                               comment.ProjectManager = (row["PM"] is DBNull) ? null : row["PM"].ToString();
                               comment.TaskManager = (row["TMFullName"] is DBNull) ? null : row["TMFullName"].ToString();
                               comments.Add(comment);
                           }
                     }
              }
                        ds.Dispose();
                        cnxn.Close();
                    }
                }
            }
            return comments;
}

在调试中检查List<Comments>对象,我可以看到它包含ProjectID字段中的有效数据。但是,当我尝试运行它时,我不断收到该错误。

这是 ascx 的(部分)标记。

<dxwgv:ASPxGridView ID="commentsASPxGridView" runat="server" AutoGenerateColumns="False" DataSourceID="CommentsDataSource">
   <Columns>
      <dxwgv:GridViewDataTextColumn FieldName="ProjectID" Caption="Project ID" VisibleIndex="7" Name="ProjectID">
      </dxwgv:GridViewDataTextColumn>
   </Columns>
</dxwgv:ASPxGridView>

<dxprt:ASPxGridViewExporter ID="gridExport" runat="server" GridViewID="commentsASPxGridView"></dxprt:ASPxGridViewExporter>        
<asp:ObjectDataSource ID="CommentsDataSource" runat="server" SelectMethod="SelCommentsByProject"  OnDataBinding="DataBindTest"
    TypeName="ESMWeb.ESMCommentService.CommentServiceClient">
    <SelectParameters>
        <asp:Parameter Name="pProjectId" DbType="String"/>
    </SelectParameters>
</asp:ObjectDataSource>
4

1 回答 1

0

ProjectID 是字段还是属性?它必须是属性才能使用 GridView

于 2013-06-06T16:05:38.707 回答