读书人

读取下拉框的值解决方法

发布时间: 2012-05-15 14:35:29 作者: rapoo

读取下拉框的值
下拉框 我是绑定到 数据库中一个表中 item_no 字段
选择 下拉框中的值 然后 按钮 触发事件 将 选中的值 写入到 LABLE中

C# code
 SqlDataReader read1 = SqlHelper.ExecuteReader(common.GetConnStr(), CommandType.Text, "select  top 20  * from item ", null);        DropDownList1.DataSource = read1;        DropDownList1.DataTextField = "item_no";        DropDownList1.DataBind(); protected void Button1_Click(object sender, EventArgs e)    {        this.Label1.Text = DropDownList1.SelectedValue.ToString();    }


现在 不管如何 选择 下拉框的值 始终读取的下拉框中第一个值 ,不知错在哪里?

[解决办法]
SqlDataReader read1 = SqlHelper.ExecuteReader(common.GetConnStr(), CommandType.Text, "select top 20 * from item ", null);
DropDownList1.DataSource = read1;
DropDownList1.DataTextField = "item_no";
DropDownList1.DataBind();
这个是写到Page_Load里面的? && 没有用 if(!Page.IsPostBack)包起来?

读书人网 >C#

热点推荐