.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

how do i get "id" of selectedvalue in dropdown list which is comming from datatable?

Posted By: Pawan kumar Shukla     Posted Date: March 27, 2011    Points:5   Category :ASP.Net
SqlCommand sqlcmd = new SqlCommand("select id, p_name from players where id_team = (select team1 from schedule where match_no='" + ddl_matchno.SelectedValue.ToString() + "')", sqlcon);
SqlDataAdapter sqlda = new SqlDataAdapter(sqlcmd);
sqlcmd.ExecuteNonQuery();
DataTable dtbat = new DataTable();
sqlda.Fill(dtbat);
ddl_bat_team.DataSource = dtbat;
ddl_bat_team.DataTextField = "p_name";
ddl_bat_team.DataBind();
lblp_name.Text = "??????????";
sqlcon.Close();

like to get "id" of selected player in ddl_bat_team to lblp_name.Text??

Responses
Author: Mahesh             
Posted Date: March 27, 2011     Points: 20   

Hi,
you can use such method to assign value to

oda.SelectCommand.CommandType = CommandType.StoredProcedure
oda.Fill(ods)
dropdown.DataSource = ods
dropdown.DataValueField = "StateProvinceDisplayID"
dropdown.DataTextField = "StateProvinceCombined"
dropdown.DataBind()

and for getting its value,

use - dropdown.selectedvalue

Please check the following link,

http://www.codersource.net/asp-net/asp-net-articles/dropdownlist-in-asp-net.aspx

Thanks & Regards
Mahesh


Author: Maverick             
Posted Date: March 28, 2011     Points: 20   

Hello,

Use datatextfield and datavaluefield property of dropdown while binding the combobox.

Then use cmbCombo.selectedvalue property to get the selected value.

Thanks,
Maverick

Thanks,
Maverick


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend