问题描述
我在ajax modalpopupExtender中有一个下拉列表。我从表中填写下拉列表然后我想在下拉列表中获取所选项目的相应ID?
##我试过这个
{
i have a dropdownlist in ajax modalpopupExtender. i fill the dropdown from a table then i am trying to get the respective id of selected item in dropdownlist??
## i have try this one
{
string select =从表格中选择Id,其中colName =' msgstr+ ddlAddDistrict.SelectedItem.Text +';
;
sda.Fill(dt);
if(dt.Rows.Count> 0)
{
int id = int.Parse(dt.Rows [0] [0] .ToString());
Response.Write(< script> alert('+ id +' )< / script>);
}
}
##我也试过这一个
string id = ddlAddDistrict.DataValueField;
一旦尝试过这个
string select = "select Id from table where colName='" + ddlAddDistrict.SelectedItem.Text + "'";
SqlDataAdapter sda = new SqlDataAdapter(select, DatabaseConnection.CreateConnection());
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
int id = int.Parse(dt.Rows[0][0].ToString());
Response.Write("<script>alert('" + id + "')</script>");
}
}
## i also tried this one
string id = ddlAddDistrict.DataValueField;
once tried this one
string MyQuery = string.Format("select Id from tableName where colName='{0}'", dropdownlsit.SelectedItem.Text);
SqlConnection con = DatabaseConnection.CreateConnection();
SqlCommand cmd = new SqlCommand(MyQuery, con);
string MyId;
MyId = cmd.ExecuteScalar() as string;
推荐答案
这篇关于当我从下拉列表中选择时,如何从表中获取ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!