2 my 00 my_00 于 2015.06.09 09:45 提问

求助:Asp.net的DataGrid里面嵌套RadioButtonList,如何获得其值?

我在Asp.net的前台页面Source里面添加了一个DataGrid,代码如下:

<asp:DataGrid ID="DataArtList" runat="server" AllowPaging="True" AutoGenerateColumns="False" CssClass="MyLine" GridLines="None" HorizontalAlign="Center" Width="100%">
<ItemStyle CssClass="MyLine" HorizontalAlign="Center" />
<HeaderStyle CssClass="Ptitle" HorizontalAlign="Center" />
<Columns>
<asp:BoundColumn DataField="ShowID" HeaderText="顺序"></asp:BoundColumn>
<asp:BoundColumn DataField="ScMain" HeaderText="内容"></asp:BoundColumn>
<asp:BoundColumn DataField="SContent1" HeaderText="优"></asp:BoundColumn>
<asp:BoundColumn DataField="SContent2" HeaderText="中"></asp:BoundColumn>
<asp:BoundColumn DataField="SContent3" HeaderText="差"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="评分">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>0</asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Visible="False" />
</asp:DataGrid> 


<asp:Button ID="BtnSave" runat="server" Text="确认提交" ToolTip="保存评价的信息" OnClick="BtnSave_Click" />

运行效果如下图:
图片说明
问题:在后台代码中:
1.我如何实现判断RadioButtonList都已经打分时,获取每一行的分数,然后分别插入数据库?

2个回答

Tiger_Zhao
Tiger_Zhao   Rxr 2015.06.09 10:01
Tiger_Zhao
Tiger_Zhao 回复my_00: 取this.DataArtList.Items[i].Cells[0].Text
2 年多之前 回复
my_00
my_00 谢谢。我如何获得如图所示每一行的序号值啊?即前台代码中的ShowID值??
2 年多之前 回复
my_00
my_00   2015.06.09 10:46

谢谢大家的慷慨帮助。但是我还是没事实现!我这样写代码为什么不行啊?那我该如何改啊?
提交按钮的后台代码如下:

  protected void BtnSave_Click(object sender, EventArgs e)
    {
   string getvalue;
        for (int i = 0; i < this.DataArtList.Items.Count; i++)
        {
            getvalue = ((RadioButtonList)this.DataArtList.Items[i].FindControl("RadioButtonList1")).SelectedValue.ToString();   //重要的是这句话
            string strSql = "insert into EvaluateTeacherGrade (ShowID,Grade,teacherID,studentID) values ('" + DataArtList.Items[i] + "','" + getvalue + "','" + Literal3.Text + "','" + Session["StudentID"] + "') ";
            SqlCommand sms_comm = new SqlCommand(strSql, sms_conn);
            sms_comm.Connection.Open();
            try
            {
                sms_comm.ExecuteNonQuery();
                Label1.Visible = true;
                Label1.Text = "提交成功";
                Label1.Style["color"] = "blue";
                DataArtListDataBound();
            }
            catch (SqlException)
            {
                Label1.Visible = true;
                Label1.Text = "提交失败";
                Label1.Style["color"] = "red";
            }
            finally
            {
                sms_comm.Connection.Close();
            }

        }
    }
Tiger_Zhao
Tiger_Zhao 试试 this.DataArtList.Items[i].Cells[5].FindControl
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片