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,