保存动态创建的单选按钮的已检查状态

时间:2013-03-06 14:28:08

标签: .net vb.net dynamic controls dotnetnuke

我有一个使用此代码的DotNetNuke皮肤:

<%@ Control language="vb" AutoEventWireup="false" Explicit="True" Inherits="DotNetNuke.UI.Skins.Skin" %>
<%@ Register TagPrefix="dnn" TagName="USER" Src="~/Admin/Skins/User.ascx" %>

<div style="float:left; width:420px; height:335px;" id="divPerguntas" runat="server"></div>
<asp:ImageButton ImageUrl="/Portals/_default/Skins/AdWin/img/Enviar.png" id="imgEnviar" runat="server" style="cursor:pointer;" />
<script runat="server">
Protected Sub EnviarClick() Handles imgEnviar.Click

    Dim conexao As SqlConnection
    Dim comando As SqlCommand
    Dim myReader As SqlDataReader
    Dim sql As String

    sql = "SELECT S.SurveyID, SO.SurveyOptionID FROM AdWin_Demo.dbo.Surveys S INNER JOIN AdWin_Demo.dbo.SurveyOptions SO ON S.SurveyID = SO.SurveyID WHERE S.VideoId = " + Request.QueryString("id") + " ORDER BY S.ViewOrder, SO.ViewOrder"
    conexao = New SqlConnection(connectionstring)
    conexao.Open()
    comando = New SqlCommand(sql, conexao)

    myReader = comando.ExecuteReader

    If myReader.HasRows Then
        Dim dt As New DataTable
        dt.Load(myReader)

            Dim dnnUserCtrl As New DotNetNuke.Entities.Users.UserController
            For Each dr As DataRow In dt.Rows
                Dim radiobuttonToCheck As RadioButton = FindControl(dr("SurveyOptionID").ToString())
            If radiobuttonToCheck.Checked = True Then
                sql = "INSERT INTO AdWin_Demo.dbo.Adwin_RespostasDadas (IDUser, SurveyOptionID) SELECT " & dnnUserCtrl.GetCurrentUserInfo.UserID & ", " & dr("SurveyOptionID").ToString()
                comando = New SqlCommand(sql, conexao)
                myReader = comando.ExecuteReader

            End If
            Next

    End If

    myReader.Close()
    conexao.Close()


End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init

    Dim conexao As SqlConnection
    Dim comando As SqlCommand
    Dim myReader As SqlDataReader
    Dim sql As String

    sql = "SELECT S.SurveyID, S.Question, SO.OptionName, SO.SurveyOptionID FROM AdWin_Demo.dbo.Surveys S INNER JOIN AdWin_Demo.dbo.SurveyOptions SO ON S.SurveyID = SO.SurveyID WHERE S.VideoId = " + Request.QueryString("id") + " ORDER BY S.ViewOrder, S.SurveyID, SO.ViewOrder"
    conexao = New SqlConnection(connectionstring)
    conexao.Open()
    comando = New SqlCommand(sql, conexao)

    myReader = comando.ExecuteReader


    If myReader.HasRows Then
        Dim dt As New DataTable
        dt.Load(myReader)

        For Each dr As DataRow In dt.Rows

            Dim rb As New RadioButton
            rb.GroupName = "Group" & dr("SurveyID").ToString()
            rb.ID = dr("SurveyOptionID").ToString()
            rb.Text = dr("OptionName").ToString()
            divPerguntas.Controls.Add(rb)
            divPerguntas.Controls.Add(New LiteralControl("<br/>"))

        Next
        Dim hr As New HtmlGenericControl("hr")
        divPerguntas.Controls.Add(hr)
    End If

    myReader.Close()
    conexao.Close()

End Sub
</script>

当我点击图像按钮时,我想向数据库发送用户的答案,但单选按钮消失,我失去了检查状态......我该如何解决?

1 个答案:

答案 0 :(得分:0)

使用DotNetNuke,您使用的代码可以更好地放入模块中,而不是将它们放入皮肤中。

查看模块开发维基,了解如何开始使用模块开发 http://www.dotnetnuke.com/Resources/Wiki/Page/Module-Development.aspx