Ticket Q534489
Visible to All Users

ASPxGridView - 'DevExpress.Web.Data.WebDataRow' does not contain a property with the name X

created 11 years ago

Hello,
I need some help, I have a GridView which it’s filled by a SqlDataReader in the Page_Load() event, but when there’s no records, this doesn’t work. I was searching on your KBs and I discovered that I need to use the ForceDataRowType() Method to force the GridView to know the DataTypes, but I don’t know how can I use this method, could you provide me an example? You can see below the way which I’m filling the GridView’s DataSource.
protected void Page_Load(object sender, EventArgs e)
{
LoadData();}
public SqlDataReader DataReader
{ get
{ string conn = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand("SELECT * FROM [Customer] ORDER BY [IdCustomer]"); cmd.CommandType = System.Data.CommandType.Text;
SqlConnection cn = new SqlConnection(conn); cmd.Connection = cn;
cn.Open(); return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}}
protected void LoadData()
{ gridView.DataSource = DataReader;
if (!IsCallback) gridView.DataBind();
}

I'm going to attach my code and you can see cleary the problem

Comments (2)
L L
Leandro Luis Almeida 11 years ago

    In another Ticket you said to use the method like this:
    protected void gridView_DataBinding(object sender, EventArgs e) {
         gridView.ForceDataRowType(typeof(System.Data.DataRow));
    }
    But I tried it and it didn't work. I attached my code and you can see cleary the problem.
    Here is the ticket link: https://www.devexpress.com/Support/Center/Question/Details/Q533971
    Thanks in advance.

      Why are you using the SqlDataReader? This object has the forward-only navigation. I would suggest you to build the DataTable object and bind it to ASPxGridView. It will be more reliable.

      Answers approved by DevExpress Support

      created 11 years ago (modified 11 years ago)

      Hello,
      The issue occurs because of the SqlDataReader class. When there's no data in the underlying datasource, the sql reader does not provide the required information to bind editors to the data source's fields.
      I suggest that you use the SqlDataSoruce control instead. Attached is the modified project.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.