[C#]RadioButtonList控件取值问题
我使用this.rbtnItems.SelectedValue取不到值.但使用Request.Form["rbtnItems"]却能取到.不知是什么原因
default.aspx
-------------------------------------------
<form id="form1" runat="server">
<table border="0" cellpadding="0" cellspacing="0" class="style1">
<tr>
<td bgcolor="#3333CC">
<asp:Label ID="LabelTitle" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td align="center" valign="middle">
<asp:RadioButtonList ID="rbtnItems" runat="server" Height="53px" Width="672px">
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td align="center" bgcolor="Blue">
<asp:Button ID="btnVote" runat="server" Text="投 票" onclick="btnVote_Click" />
<asp:Button ID="btnShow" runat="server" Text="结 果" />
</td>
</tr>
</table>
</form>
-------------------------------------------
default.aspx.cs
-------------------------------------------
//创建Conn对象
SqlConnection objConn = DB.createConnection();
//打开Conn
objConn.Open();
//建立和查询
SqlCommand cmd = new SqlCommand("select voteTitle from voteMaster where voteID=" + this.voteid, objConn);
string strTitle = Convert.ToString(cmd.ExecuteScalar());
this.LabelTitle.Text = strTitle;
SqlCommand cmdItems = new SqlCommand("select * from voteDetails where voteId=" + this.voteid, objConn);
SqlDataReader objRs = cmdItems.ExecuteReader();
this.rbtnItems.DataSource = objRs;
this.rbtnItems.DataTextField = "voteItem";
this.rbtnItems.DataValueField = "voteDetailsID";
this.rbtnItems.DataBind();
objRs.Close();
objConn.Close();
------解决方案--------------------//是否做了回传判断
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//绑定数据
}
}
------解决方案--------------------可以这样:
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "Default18.aspx.cs " Inherits= "Default18 " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<asp:Repeater ID= "Repeater1 " runat= "server " OnItemDataBound= "Repeater1_ItemDataBound " >
<ItemTemplate>
<div>
<!--问题-->
<asp:Label ID= &