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
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.