关于RadioButton选中判断问题

来源:百度知道 编辑:UC知道 时间:2024/05/26 11:27:49
C#:
protected void submit_Click(object sender, EventArgs e)
{
for (int i = 0; i < ds.Tables["test_temp1"].Rows.Count; i++)
{
foreach (DataListItem dli in DataList1.Items)
{
RadioButton rbtn1 = (RadioButton)DataList1.Items[i].FindControl("RadioButton1");
RadioButton rbtn2 = (RadioButton)DataList1.Items[i].FindControl("RadioButton2");
RadioButton rbtn3 = (RadioButton)DataList1.Items[i].FindControl("RadioButton3");
RadioButton rbtn4 = (RadioButton)DataList1.Items[i].FindControl("RadioButton4");
RadioButton rbtn5 = (RadioButton)DataList1.Items[i].FindControl("RadioButton5");
if (rbtn1.Checked == true)
{
score = System.Convert.ToInt32(ds.Tables["test_temp1"].DefaultView[0].

把ds.Tables["test_temp1"].DefaultView[0].Row[10]改成ds.Tables["test_temp1"].DefaultView[0].Row[10].ToString()

因为你ds.Tables["test_temp1"].DefaultView[0].Row[10]返回得是DataRow类型得,它的值应该是个集合,所以ds.Tables["test_temp1"].DefaultView[0].Row[10].ToString()返回是它的类型。全是字符串,所以出现提示“输入字符串的格式不正确。”
不知道你想要做什么,如果想获取整行的值用ItemArray属性
ds.Tables["test_temp1"].DefaultView[0].Row[10].ItemArray返回的是数组,如果想得到某一个用ds.Tables["test_temp1"].DefaultView[0].Row[10].ItemArray[i]

score = System.Convert.ToInt32(ds.Tables["test_temp1"].DefaultView[0].Row[12]==DbNull.Value?"0":ds.Tables["test_temp1"].DefaultView[0].Row[12]);

这个好回答:是