页加加载时获取DropDownList怎样绑定数据库中已选的值,为什么为何获取的总是第一值?
protectedvoidPage_Load(objectsender,EventArgse){Page.Title=DataClass.GetApplication("...
protected void Page_Load(object sender, EventArgs e)
{
Page.Title = DataClass.GetApplication("webname") + " - 后台管理 - " + "编辑新闻";
//判断管理员是否登录
//DataClass.AdminValidate();
if (!IsPostBack)
{
string strSQL;
strSQL = "select * from nts_newsclass order by sort";
Ddl_Class.DataSource = DataClass.GetDataReader(strSQL);
Ddl_Class.DataTextField = "classname";
Ddl_Class.DataValueField = "id";
Ddl_Class.DataBind();
strSQL = "select * from nts_indexdata where id=" + Request.QueryString["id"].ToString();
IDataReader dr = DataClass.GetDataReader(strSQL);
dr.Read();
foreach (ListItem item in Ddl_Class.Items)
{
if (item.Value == dr["id"].ToString())
{
item.Selected = true;
break;
}
}
img_Pic.ImageUrl= dr["picurl"].ToString();
tbx_WebUrl.Text = dr["weburl"].ToString();
Txt_Title.Text =DataClass.HtmlDecode(dr["title"].ToString());
Txt_Content.Text =DataClass.HtmlDecode(dr["content"].ToString());
dr.Close();
}
请各位大侠帮忙看看。感谢! 展开
{
Page.Title = DataClass.GetApplication("webname") + " - 后台管理 - " + "编辑新闻";
//判断管理员是否登录
//DataClass.AdminValidate();
if (!IsPostBack)
{
string strSQL;
strSQL = "select * from nts_newsclass order by sort";
Ddl_Class.DataSource = DataClass.GetDataReader(strSQL);
Ddl_Class.DataTextField = "classname";
Ddl_Class.DataValueField = "id";
Ddl_Class.DataBind();
strSQL = "select * from nts_indexdata where id=" + Request.QueryString["id"].ToString();
IDataReader dr = DataClass.GetDataReader(strSQL);
dr.Read();
foreach (ListItem item in Ddl_Class.Items)
{
if (item.Value == dr["id"].ToString())
{
item.Selected = true;
break;
}
}
img_Pic.ImageUrl= dr["picurl"].ToString();
tbx_WebUrl.Text = dr["weburl"].ToString();
Txt_Title.Text =DataClass.HtmlDecode(dr["title"].ToString());
Txt_Content.Text =DataClass.HtmlDecode(dr["content"].ToString());
dr.Close();
}
请各位大侠帮忙看看。感谢! 展开
5个回答
展开全部
foreach (ListItem item in Ddl_Class.Items)
{
if (item.Value == dr["id"].ToString())
{
// item.Selected = true;
break;
}
item.SelectedValue=item.value
{
if (item.Value == dr["id"].ToString())
{
// item.Selected = true;
break;
}
item.SelectedValue=item.value
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
this.ddlProvinceList.SelectedIndex = this.ddlProvinceList.Items.IndexOf(this.ddlProvinceList.Items.FindByValue(“选中的SelectValue”));
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的选择值没变化是selectedvalue
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ddr.selectedValue=value
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询