【发布时间】:2017-05-06 23:39:47
【问题描述】:
我绑定了我的 RadioButtonList,但是当我在单击 RadiobuttonList 后选择项目并使用按钮时,将选中的项目更改为第一行表单绑定
当我使用 autopostback='true" 和 RadioButtonList 作为选择发件人时也会发生这种情况
if (!IsPostBack)
{
using (SqlConnection con = new SqlConnection(@"server=localhost; database=PS_User; trusted_connection=true;"))
{
con.Open();
SqlCommand cmd = new SqlCommand(@"Select * from S1 WHERE PART =@1 AND PART IS NOT NULL Order by point", con);
cmd.Parameters.AddWithValue("@0", 0);
cmd.Parameters.AddWithValue("@1", 1);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
RadioButtonList1.DataTextField = "Name";
RadioButtonList1.DataValueField = "Point";
RadioButtonList1.DataSource = ds.Tables[0];
RadioButtonList1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedIndex > -1)
{
Label1.Text = "You chose: " +
RadioButtonList1.SelectedItem.Text;
}
}
【问题讨论】:
-
我已经测试了按钮点击和
OnSelectedIndexChanged自动回发设置为真。它两次都按预期工作。你在使用UpdatePanel或类似的东西吗?因为问题不在上面的sn-p中。