I have a problem in WPF using DataGrid, I am using SQLDataReader and when I populate record from Datatable to Datagrid there are no record but it hasRows my Code is this.
try
{
string commandText = "dbo.sp_select_survey";
SqlConnection conn = new SqlConnection("Data Source=IT-PC1;Initial Catalog=gcserp;User ID=test;Password=test;Initial Catalog=gcserp;Integrated Security=True");
SqlCommand cmd = new SqlCommand(commandText, conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandTimeout = 600;
conn.Open();
SqlDataReader objRDR = cmd.ExecuteReader((CommandBehavior.CloseConnection));
DataTable dt = new DataTable();
dt.Load(objRDR);
dataGrid1.ItemsSource=dt.DefaultView;
}
catch
{
}
not sure what your aspx page looks like and what setting you have in you datagrid, but I would first test the datagrid without defining any boundcolumns or customtemplate columns and make sure the autogeneratecolumns is set to true. Just something basic like to see if your data will bind to the grid:
Also make sure you are not returning any null values and include ISNULL(field,”) in you query.
Finally in .net framework 4 you should be using gridview instead of datagrid…not sure if that is a typo.