Joma Rajab

Joma Rajab

  • NA
  • 110
  • 51.2k

how to display the value of the column in drop down list

Aug 29 2016 10:15 AM
i need to show the selected value from database in drop down list and this drop down list contains items on of them is the selected one from database 
 
  1. asp.net code   
  2.   
  3.  <asp:DropDownList ID="DropDownList3" runat="server" EnableViewState="true" DataSourceID="SqlDataSource7"   AppendDataBoundItems="true" DataTextField="Name" DataValueField="SId" Width="130px" Height="25px"> <asp:ListItem>Select School</asp:ListItem> </asp:DropDownList>  
  4.  <asp:SqlDataSource ID="SqlDataSource7" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [SId],[Name] FROM [School]"></asp:SqlDataSource>  
  5.   
  6.   
  7.   
  8.   
  9.   
  10.   
  11.  SqlDataReader myReader = null;  
  12.             SqlCommand query = new SqlCommand(@"select * from dbo.Cousres INNER JOIN dbo.School ON   
  13.                 dbo.School.SId=dbo.Cousres.SId where dbo.Cousres.CourseId='" + TextBox7.Text + "'", conn);  
  14.             SqlDataAdapter da = new SqlDataAdapter();           
  15.             myReader = query.ExecuteReader();              
  16.             while (myReader.Read())     
  17.             {  
  18.                 TextBox3.Text = (myReader["CourseId"].ToString());   
  19.                 TextBox4.Text = (myReader["CousreName"].ToString());  
  20.                 DropDownList3.SelectedValue= (myReader["Name"].ToString());  
  21.                 Edit.Visible = false;  
  22.             }  
please help  
 thnak you  

Answers (1)