我现在把一radiobutton与datalist绑定  但是我运行页面的时候  虽然选定了 不过其check属性依然为false(设断点调试的时候发现的)绑定代码:
<ItemTemplate>
<%#container.dataitem("ques")%>
<BR>
<asp:RadioButton id=rb1 Text='<%#container.dataitem("ansa")%>' Runat="server" GroupName="g1">
</asp:RadioButton><BR>
<asp:RadioButton id=rb2 Text='<%#container.dataitem("ansb")%>' Runat="server" GroupName="g1">
</asp:RadioButton><BR>
<asp:RadioButton id=rb3 Text='<%#container.dataitem("ansc")%>' Runat="server" GroupName="g1">
</asp:RadioButton><BR>
<asp:RadioButton id=rb4 Text='<%#container.dataitem("ansd")%>' Runat="server" GroupName="g1">
</asp:RadioButton><BR>
<P>
后台代码:  For i = 0 To dst.Items.Count - 1
            Dim dli As DataListItem = dst.Items(i)
            Dim option1 As RadioButton = dli.FindControl("rb1")
            Dim option2 As RadioButton = dli.FindControl("rb2")
            Dim option3 As RadioButton = dli.FindControl("rb3")
            Dim option4 As RadioButton = dli.FindControl("rb4")
            Dim num As Integer
            Dim quesanse As Label = dli.FindControl("L1")
            num = 0
            Dim selectanse As String
            If option1.Checked Then
                selectanse = "A"            ElseIf option2.Checked Then
                selectanse = "B"
            ElseIf option3.Checked Then
                selectanse = "C"
            ElseIf option4.Checked Then
                selectanse = " D"
            Else
                selectanse = 0
不过调试的时候 每次selectanse都等于 0把RadioButton控件属性设为AutoPostBack社为true后  在预览页面点了 radiobutton都没反映~~~~
   多谢各位相助!!!!!!!!

解决方案 »

  1.   

    For i = 0 To dst.Items.Count - 1
                Dim dli As DataListItem = dst.Items(i)
                Dim option1 As RadioButton = dli.FindControl("rb1")
                Dim option2 As RadioButton = dli.FindControl("rb2")
                Dim option3 As RadioButton = dli.FindControl("rb3")
                Dim option4 As RadioButton = dli.FindControl("rb4")
                Dim num As Integer
                Dim quesanse As Label = dli.FindControl("L1")
                num = 0
                Dim selectanse As String
                If option1.Checked Then
                    selectanse = "A"
                    break
                ElseIf option2.Checked Then
                    selectanse = "B"
                    break
                ElseIf option3.Checked Then
                    selectanse = "C"
                    break
                ElseIf option4.Checked Then
                    selectanse = " D"
                    break
                Else
                    selectanse = 0
                    break
    加break,当选中后就跳出循环即可
      

  2.   

    我做的是一考试系统   在判卷的时候 要判断选择了哪一项   这道题判完  还有下道呢~~  如果跳出的话   不就是只有一道题了 
         我的问题是   假如你做题的时候选择了答案A但是在判卷过程中-A选择项radiobutton的checked的属性依然是faulse~~~
          
        不过依然感谢你的参与
      

  3.   

    问题可能在于,你的datalist数据的绑定是不是放在!IsPostBack中进行?如果没有,那么在每次页面刷新时,都将你的选择重置了,当然得不到值.
    而且你上面的取值语句应该也有问题.
    if not IsPostBack then
    //绑定datalist
    end if取值定义
    Dim option1 As RadioButton = Ctype(dli.FindControl("rb1"),RadioButton)