Display gridview in pageload event

Posted by Nageswari under C# category on | Views : 6989
Hi I want to get the gridview in pageload event without having a button,I have one dropdownlist if i select one value in dropdownlist
the details should be displayed in gridview in pageload event.

Here is my code...am not getting it.... Any help would be appreciated....

protected void Page_Load(object sender, EventArgs e)
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString);

if (DDLSelectReport.SelectedValue == "Newly Purchased Book")
string sql = "select AccessionNo,ISBN,BookTitle,BookAuthor,ReceivedDate,Category,RackNo from LibManAddBook";

SqlCommand cmd = new SqlCommand(sql, con);
GridView1.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (DDLSelectReport.SelectedValue == "Newly Purchased CD")

string sql1 = "select AccessionNo,CDTitle,CDAuthor,ReceivedDate,Category,RackNo from LibManAddCD1";
SqlCommand cmd = new SqlCommand(sql1, con);
GridView2.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection);


Comments or Responses

Posted by: Shankul2784 on: 8/5/2010 Level:Bronze | Status: [Member]

Here your question is little bit confusing. If you dont want a button then please write your code
in the dropdown_selectedindexchanged event and change the dropdown property to
autopostback ="true".

Posted by: Nageswari on: 8/6/2010 Level:Starter | Status: [Member]
Thanks a lot it's working now.......

Login to post response