Display gridview in pageload event

Nageswari
Posted by Nageswari under C# category on | Views : 6423
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);
con.Open();
GridView1.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataBind();
}
if (DDLSelectReport.SelectedValue == "Newly Purchased CD")
{

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

}
}

Comments or Responses

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

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