1 Replies - 1941 Views - Last Post: 20 December 2012 - 06:44 AM Rate Topic: -----

#1 yadnya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-December 12

retrieving checkboxlist saved data from the sql database in asp.net

Posted 20 December 2012 - 03:27 AM


Imports System.Data
Imports System.Data.SqlClient
Partial Class TimeTable_frmAssignSlot
    Inherits System.Web.UI.Page
    Private SlotID As Integer
    Private objTTInfo As New BL_Timetable
    Dim str1 As String = ConfigurationSettings.AppSettings("conString")
   
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        
        If Not IsPostBack Then
            Dim strID As String = Request.QueryString("id")
            Dim strName As String = Request.QueryString("slot")
            '4:          Dim strLocation As String = Request.QueryString("loc")
            '5:          lblID.Text = strID
            '6:          lblName.Text = strName
            '7:          lblLocation.Text = strLocation
            lblSlotName.Text = strName
            lblNote.Text = "Select Classes for the " + strName + " " + "slot"
            BindCheckboxlist()

            'CheckRecord()
        End If


    End Sub
    
    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSave.Click
        If Request.QueryString("id") Is Nothing Then
            For i = 0 To chkClassDivision.Items.Count - 1

                If chkClassDivision.Items(i).Selected Then
                    objTTInfo.pk_ClassDivSlot_ID = "0"
                    objTTInfo.SlotName = lblSlotName.Text
                    objTTInfo.ClassDivName = chkClassDivision.Items(i).Text
                    objTTInfo.isChecked = chkClassDivision.Items(i).Selected
                    objTTInfo.AssignSlotToClassDiv()
                End If

            Next
        End If
    End Sub
    
    Private Sub BindCheckboxlist()

        Dim objConn As SqlConnection = New SqlConnection(str1)
        Dim objCmd As SqlCommand = New SqlCommand("select tbl_Master_ClassMaster .ClassName +'_'+tbl_Master_DivisionMaster .DivName  as CLASSDIV from tbl_Master_ClassMaster ,tbl_Master_DivisionMaster ,tbl_Master_ClassDivisionRelation where tbl_Master_ClassDivisionRelation .fk_ClassId =tbl_Master_ClassMaster .Pk_classId and tbl_Master_ClassDivisionRelation .fk_Divid =tbl_Master_DivisionMaster .Pk_divId ", objConn)
        chkClassDivision.DataTextField = "CLASSDIV"
        chkClassDivision.DataValueField = "CLASSDIV"
        objConn.Open()
        chkClassDivision.DataSource = objCmd.ExecuteReader
        chkClassDivision.DataBind()

        objConn.Close()

    End Sub
    Private Sub CheckRecord()
       
        Dim objConn1 As SqlConnection = New SqlConnection(str1)
        Dim objCmd1 As SqlCommand = New SqlCommand("select * from tbl_Master_AssignSlotToClassDiv", objConn1)
        objConn1.Open()

        Dim objReader As SqlDataReader
        objReader = objCmd1.ExecuteReader()
        While (objReader.Read())
            Dim currentCheckbox As New ListItem()
            currentCheckbox.Text = objReader("ClassDivName").ToString()
            currentCheckbox.Value = objReader("pk_ClassDivSlot_ID").ToString()
            currentCheckbox.Selected = Convert.ToBoolean(objReader("isChecked"))
            chkClassDivision.Items.Add(currentCheckbox)

        End While
    objConn1.Close()



    End Sub
End Class

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: retrieving checkboxlist saved data from the sql database in asp.net

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

Re: retrieving checkboxlist saved data from the sql database in asp.net

Posted 20 December 2012 - 06:44 AM

What is your question? What problems are you having? Are you getting any errors or is it just not working like you think it should? Have you stepped through the code with the debugger to see what it's doing?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1