Drop down selected value in asp.net
In my database I have to columns i.e GroupName,UserName & I have a drop down ,when I select the drop down item(GroupName),in label or text box I need to display UserName belongs to the group so can any one help me ..it's very urgent
Nanhe SiddiquePosted May 12, 2015, 11:55 PM
use selected index changed event of drop down list
protected void ddlGroupName_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection connection = new MySqlConnection("server=192.168.1.100;username=mcubic;password=mcs@2011$;database=mcubic;"); string query = "select username from table1 where Goupname = '" + ddlGroupName.SelectedItem.ToString() + "' SqlCommand command = new MySqlCommand(query, connection); connection.Open(); SqlDataReader Reader = command.ExecuteReader(); while (Reader.Read()) { label1.Text = Reader[0].ToString(); } connection.Close(); }
it think it may help you
Usha RajPosted May 13, 2015, 12:52 AM
Dipankar BiswasPosted May 13, 2015, 12:00 AM
Usha
Check this link to help..http://www.java2s.com/Code/ASP/ADO.net-Database/ReaddatafromdatabaseinaspdropdownlistselectionchangedeventC.htm
Venkat KumarPosted May 12, 2015, 11:56 PM
This is the flow.
Double click on the dropdownlist. In SelecteIndexChanged Event write the below code.
SqlConnection con = new sqlConnection();
Con.connectionstring="Write your Connection string";
string groupname= dropdownlist1.selectedvalue.test;
sqlcommand cmd = new sqlcommand();
cmd.commandtext="select Username from table where GroupName="'+groupname+'"";
sqldatareader dr=cmd.executeReader();
lable1.text=dr[0].ToString();