protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GridView1.DataSource =GetTopics();
this.GridView1.DataBind();
}
}
private SqlDataReader GetTopics()
{
SqlDataReader dr = null;
using (SqlConnection conn = new SqlConnection(strconn))
{
try
{
conn.Open();
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "select * from Topics";
dr = comm.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException ex)
{
throw new Exception(ex.Message, ex);
}
finally
{
conn.Close();
}
}
return dr;
}