i fill the dropdownlist dynamically from database then when i try to get the corresponding id of selected item from dropdown then it does not give me the id. i have a button haing click event which contain the code below the .aspx
this is my .aspx file
TargetControlID="lbtnAddNewPS"
CancelControlID="btncanceladdNewPs" BackgroundCssClass="Background" OnLoad="mp1_Load">
Add New Police Station
--%>
code behind file .aspx.cs
string MyQuery = string.Format("select DistrictId from District where DistrictName='{0}'", ddlAddDistrict.SelectedItem.Text);
SqlConnection con = DatabaseConnection.CreateConnection();
SqlCommand cmd = new SqlCommand(MyQuery, con);
string MyId;
MyId = cmd.ExecuteScalar() as string;
Response.Write("");
Response.Write("");
string insert = "insert into PoliceStation values('"+MyId+"','"+policeStation+"')";
InsertIntoDB.InsertQuery(insert);
if (InsertIntoDB.count > 0)
{
Response.Write("");
InsertIntoDB.count = 0;
}
else {
Response.Write("");
}
it does not work at all please tell me i m being stuck in this problem and make al0t of changes still insert in the second table failed because the id which i want to pick up when the user make some selection from dropdownlist.

Rojalin SahooRank #2,919 · 493 reputationPosted Sep 6, 2015, 11:25 PM EDT
Baimey RajeshRank #1,338 · 1.3K reputationPosted Sep 6, 2015, 11:42 PM EDT
Miraj Ahmad19 reputationPosted Sep 14, 2015, 5:03 AM EDT
Miraj Ahmad19 reputationPosted Sep 14, 2015, 5:11 AM EDT
Baimey RajeshRank #1,338 · 1.3K reputationPosted Sep 14, 2015, 10:41 PM EDT