Imports System.Drawing
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.SqlClient


Public Class servercontrols3
    Inherits System.Web.UI.Page
    Protected WithEvents radio1 As System.Web.UI.WebControls.RadioButtonList
    Protected WithEvents myspan As System.Web.UI.HtmlControls.HtmlGenericControl
    Protected WithEvents button1 As System.Web.UI.WebControls.Button
    
#Region " Web Forms Designer Generated Code "
    
    'CODEGEN: This procedure is required by the Web Form Designer
    'Do not modify it using the code editor.
    Private Sub InitializeComponent()

    End Sub

#End Region

    Protected Sub Page_Init(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
    Function GetDataSet(ByVal sqlText As String, ByVal dsName As String) As DataSet

        Dim myConnection As New SqlConnection(Application("DBPubsConnectionString").ToString())
        Dim myCommand As New SqlDataAdapter(sqlText, myConnection)

        Dim ds As New DataSet()
        myCommand.Fill(ds, dsName)

        Return ds

    End Function

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        Dim sqlText As String = "SELECT title_id, title FROM titles ORDER BY title"
        Dim ds As DataSet = GetDataSet(sqlText, "Titles")

        radio1().DataSource = ds.Tables("Titles").DefaultView
        radio1().DataValueField = "title_id"
        radio1().DataTextField = "Title"
        DataBind()
        myspan().InnerHtml = "Select your favorite title<br>"
    End Sub

End Class
