我在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都已经打分时,获取每一行的分数,然后分别插入数据库?
在asp.net中如何获取asp:DataList中子控件asp:RadioButtonList的值
谢谢大家的慷慨帮助。但是我还是没事实现!我这样写代码为什么不行啊?那我该如何改啊?
提交按钮的后台代码如下:
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();
}
}
}