locked
How to populate RadioButtonList using 3-tier Logic RRS feed

  • Question

  • User1080340250 posted

    The below code doesn't work becuase I need to somehow feed the DataText and Value fields. I need to somehow amend the code to allow me to populate my RadioButtonList and to fit inside my 3-tier architecture.  My first time doing this so I'm a little lost.

    rblAnswers.DataSource = rblDataSource(QuestionID)
    ' rblAnswers.DataTextField = dt.Columns(1).ToString
    ' rblAnswers.DataValueField = dt.Columns(0).ToString
    
    'Calls
    
    
     Private Function rblDataSource(ByVal QuestionID As Integer) As DataTable
    
            Dim SurveyID As Integer = Convert.ToInt32(Request.QueryString("id"))
    
            Dim p As New SurveyDAL()
            Dim dTable As New DataTable()
            Try
                dTable = p.GetAnswers(SurveyID, QuestionID)
            Catch ee As Exception
                lblMessage.Text = ee.Message.ToString()
            Finally
                p = Nothing
            End Try
    
            Return dTable
        End Function
    
    
    'Which Calls
    
    Public Function GetAnswers(ByVal ID As Integer, ByVal Question As Integer) As DataTable
    
            Dim conn As New SqlConnection(connStr)
            Dim dAd As New SqlDataAdapter("GetAnswers", conn)
            dAd.SelectCommand.CommandType = CommandType.StoredProcedure
            dAd.SelectCommand.Parameters.AddWithValue("@ID", ID)
            dAd.SelectCommand.Parameters.AddWithValue("@Question", Question)
    
            Dim dSet As New DataSet()
            Try
                dAd.Fill(dSet, "Answers")
                Return dSet.Tables("Answers")
    
    
            Catch
                Throw
            Finally
                dSet.Dispose()
                dAd.Dispose()
                conn.Close()
                conn.Dispose()
            End Try
        End Function

     
    Thursday, October 21, 2010 11:00 AM

Answers

  • User2024939479 posted

    Hi, Please make sure that your DataTable is not null or empty by debugging. After that,for binding data to control use the following code:

    rblAnswers.DataSource = rblDataSource(QuestionID);
    rblAnswers.DataTextField = "Column1Name";
    rblAnswers.DataValueField = "Column2Name";
    rblAnswers.DataBind();


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 21, 2010 11:57 PM

All replies

  • User2024939479 posted

    Hi, Please make sure that your DataTable is not null or empty by debugging. After that,for binding data to control use the following code:

    rblAnswers.DataSource = rblDataSource(QuestionID);
    rblAnswers.DataTextField = "Column1Name";
    rblAnswers.DataValueField = "Column2Name";
    rblAnswers.DataBind();


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 21, 2010 11:57 PM
  • User1080340250 posted

    That did it, thx! 

    Friday, October 22, 2010 10:45 AM