Ticket Q533971
Visible to All Users

ASPxGridView - How to use ForceDataRowType method

created 11 years ago

Good Morning,
I need some
help, I have a GridView wich 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();

}

Thanks in advance,

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello,
Yes, the ASPxGridView.ForceDataRowType method is intended to be used when the grid's data source is empty.
It is recommended to call this method by handling the ASPxGridView.DataBinding event, i.e., before data retrieving:

C#
protected void gridView_DataBinding(object sender, EventArgs e) { gridView.ForceDataRowType(typeof(System.Data.DataRow)); }
    Comments (1)
    DevExpress Support Team 11 years ago

      [DXSupport: created from the owner's answer]
      It doesn't work, I'm going to attach my code and you can see cleary the problem.

      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.