无法获取radiobuttonlist的选中项?
程序如下:stringSql="UpdatefromVoteDetailwhereVoteDetaileId="+this.RadioButtonList1.Select...
程序如下:
string Sql = "Update from VoteDetail where VoteDetaileId=" + this.RadioButtonList1.SelectedValue;
在明明已经选择了一项的情况下,取出的却是空值!
求教
绑定数据的代码为:
string sql = "Select * from VoteDetail where id="+ID;
SqlDataReader sdr=DB.ExecSqlReader(sql);
RadioButtonList1.DataSource = sdr;
RadioButtonList1.DataTextField = "VoteItem";
RadioButtonList1.DataValueField = "VoteDetaileId";
RadioButtonList1.DataBind(); //将数据绑定到单选列表控件
sdr.Close(); 展开
string Sql = "Update from VoteDetail where VoteDetaileId=" + this.RadioButtonList1.SelectedValue;
在明明已经选择了一项的情况下,取出的却是空值!
求教
绑定数据的代码为:
string sql = "Select * from VoteDetail where id="+ID;
SqlDataReader sdr=DB.ExecSqlReader(sql);
RadioButtonList1.DataSource = sdr;
RadioButtonList1.DataTextField = "VoteItem";
RadioButtonList1.DataValueField = "VoteDetaileId";
RadioButtonList1.DataBind(); //将数据绑定到单选列表控件
sdr.Close(); 展开
2个回答
展开全部
你把Pageload 里的绑定代码放在 !IsPostBack 里
这样
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SqlExpress;Initial Catalog=MSPetShop4;Integrated Security=True");
con.Open();
DataSet ds = new DataSet();
//SqlCommand cmd = new SqlCommand("Select * from Category ");
SqlDataAdapter sda = new SqlDataAdapter("Select * from Category ", con);
sda.Fill(ds);
this.RadioButtonList1.DataSource = ds;
this.RadioButtonList1.DataTextField = "Name";
this.RadioButtonList1.DataValueField = "CategoryId";
RadioButtonList1.DataBind();
con.Close();
}
这样就不会老是刷新覆盖结果了。这个很关键多注意点。
RadioButtonList1.SelectedItem 获取选中项的值
RadioButtonList1.SelectedValue获取选中项的主键
这样
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SqlExpress;Initial Catalog=MSPetShop4;Integrated Security=True");
con.Open();
DataSet ds = new DataSet();
//SqlCommand cmd = new SqlCommand("Select * from Category ");
SqlDataAdapter sda = new SqlDataAdapter("Select * from Category ", con);
sda.Fill(ds);
this.RadioButtonList1.DataSource = ds;
this.RadioButtonList1.DataTextField = "Name";
this.RadioButtonList1.DataValueField = "CategoryId";
RadioButtonList1.DataBind();
con.Close();
}
这样就不会老是刷新覆盖结果了。这个很关键多注意点。
RadioButtonList1.SelectedItem 获取选中项的值
RadioButtonList1.SelectedValue获取选中项的主键
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询