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.
5 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Baimey RajeshPosted Sep 15, 2015, 2:41 AM
Miraj AhmadPosted Sep 14, 2015, 9:11 AM
Miraj AhmadPosted Sep 14, 2015, 9:03 AM
Baimey RajeshPosted Sep 7, 2015, 3:42 AM
Rojalin SahooPosted Sep 7, 2015, 3:25 AM