日期:2014-05-18 浏览次数:20580 次
RadioButtonList rb = (RadioButtonList)FormView1.FindControl("S_answer");
//这块你确定你找到了这个东西了 ?
//使用的时候也不判断一下是不是null?
//调试一下 看看你这块是不是得到这个东西了 要是没有找到 重新看看你找哪个控件的代码
string s = rb.SelectedValue.ToString();
------解决方案--------------------
RadioButtonList 用(SelectedValue.ToString();)这个貌似不对吧 ~~~
我记得应该是 :SelectedItem.Text;
------解决方案--------------------
你的
RadioButtonList
放在了
<EditItemTemplate></EditItemTemplate>
里面了吗
参见
http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.formview.itemupdating.aspx
------解决方案--------------------
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
RadioButtonList RadioButtonList1 = FormView1.FindControl("RadioButtonList1") as RadioButtonList;
Response.Write(RadioButtonList1.SelectedValue);
//为了测试。不继续执行
e.Cancel = true;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form runat="server">
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Edit"
OnItemUpdating="FormView1_ItemUpdating">
<EditItemTemplate>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="A">A</asp:ListItem>
<asp:ListItem Value="B">B</asp:ListItem>
<asp:ListItem Value="C">C</asp:ListItem>
<asp:ListItem Value="D">D</asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="x" runat="server" CommandName="Update" Text="Update" />
</EditItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Provider=SQLOLEDB;Data Source=.;Persist Security Info=True;Password=xx;User ID=sa;Initial Catalog=xxxxx"
ProviderName="System.Data.OleDb" SelectCommand="SELECT Title FROM [Article]"
UpdateCommand="Update xxx"></asp:SqlDataSource>
</form>
</body>
</html>