dropdownlist数据绑定的问题
protected void Page_Load(object sender, EventArgs e)
{
DataClassesDataContext dcdc = new DataClassesDataContext(ConfigurationManager.ConnectionStrings["db_16ConnectionString"].ConnectionString.ToString());
var result = from r in dcdc.Leaveword
select new
{
id = r.id,
title = r.Title,
};
ddl1.DataSource = result;
ddl1.DataTextField = "title";
ddl1.DataValueField = "id";
ddl1.DataBind();
}
protected void btnChange_Click(object sender, EventArgs e)
{
DataClassesDataContext dcdc = new DataClassesDataContext(ConfigurationManager.ConnectionStrings["db_16ConnectionString"].ConnectionString.ToString());
int id =Convert.ToInt32(ddl1.SelectedValue);
Response.Write(id.ToString());
//var result = from r in dcdc.Leaveword
// where r.id == id
// select r;
//foreach (Leaveword lw in result)
//{
// lw.Message = txtMessage.Text;
//}
//dcdc.SubmitChanges();
//Response.Write("<script language=javascript>alert('修改成功!')</script>");
}
为什么输出的总是1 难道dropdownlist值没有正确绑定吗 ?
------最佳解决方案--------------------if(!IsPostBack) 啊
为什么PageLoad总不喜欢加这一句呢
------其他解决方案--------------------我也有数据绑定的问题,是gridview中某列是dropdownlist,我在databind()的时候报错,你看看能帮我解决么?
http://bbs.csdn.net/topics/390307128
------其他解决方案--------------------
select new
{
&n