asp.net - populate gridview on dropdownlist indexchanged -


I have the gridview that populates the date from the database. I want to change the data on the dropdown. I database when I choose I try to get one more data, but this code is my code

  Secure Zero Page_load (object sender, event year e) {if (IsPostBack) {BindData (); }} Private void BindData () {if (ddlTguidedit.SelectedIndex == 0) {select string strQuery = "[Pdfid], [Arpdf_name], [Arpdf_des], [pdf_date] [books_alaa] from. [Dbo]. [Tbl_uploadpdf] "; SqlCommand CMD = new SQL Commands (Structure); GridView1.DataSource = GateData (CMD); GridView1.DataBind (); } Else {string strQuery = "Select Pdfid, Enpdf_name Arpdf_name, Enpdf_des Arpdf_des, pdf_url, as as pdf_date" Tbl_uploadpdf of; SqlCommand CMD = new SQL Commands (Structure); GridView1.DataSource = GateData (CMD); GridView1.DataBind (); }} Private Datatable GetData (SqlCommand CMD) {DataTable dt = New DataTable (); SqlConnection con = new SqlConnection (strConnString); SqlDataAdapter sda = New SqlDataAdapter (); Cmd.CommandType = CommandType.Text; Cmd.Connection = con; Con.Open (); Sda.SelectCommand = cmd; Sda.fill (dt); Return DT; } Void ddlTguidedit_SelectedIndexChanged (object sender, EventArgs e) protected {if (ddlTguidedit.SelectedIndex == 0) {select string strQuery = "[Pdfid], [Arpdf_name], [Arpdf_des], [pdf_date] from [books_alaa]. [Dbo] . [Tbl_uploadpdf] "; SqlCommand CMD = new SQL Commands (Structure); GridView1.DataSource = GateData (CMD); GridView1.DataBind (); } Else {string strQuery = "Select Pdfid, Enpdf_name Arpdf_name, Enpdf_des Arpdf_des, pdf_url, as as pdf_date" Tbl_uploadpdf of; SqlCommand CMD = new SQL Commands (Structure); GridView1.DataSource = GateData (CMD); GridView1.DataBind (); }}  

Why does not this work ??

Remove from BindData ()! With IsPostBack () you are loading grid data on the dropdown list selected index switch . ! No need for BindData () function to be in IsPostBack () . The bundadata () function always depends on the dropdownist on the index, it always takes the index as 0.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -