<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.oledb" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
    Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<script language="vb" runat="server">
   
    
    Sub BindGrid()
        Dim connection As OleDbConnection
        connection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\emong\Documents\Visual Studio 2008\WebSite1\App_Data/dbLupon.mdb")
        connection.Open()
        
        Dim command As OleDbCommand
        command = New OleDbCommand("Select * from tblLupon_C WHERE REGION_C = '" & lblRegion.Text & "' AND PROVINCE_C = '" & lblProvince.Text & "' AND CITYMUN_C = '" & cmbCity.SelectedValue & "' AND BARANGAY_C = '" & cmbBrgy.SelectedValue & "'", connection)
        Dim DataReader As OleDbDataReader
        DataReader = command.ExecuteReader()
        GridView1.DataSource = DataReader
        GridView1.DataBind()
        connection.Close()
    End Sub
     
    Private Sub Page_Load()
        If Not IsPostBack Then
            BindGrid()
        End If
    End Sub
    
    
    Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
        GridView1.EditIndex = e.NewEditIndex
        Call BindGrid()
    End Sub
   
    Protected Sub Gridview1_RowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs)
        GridView1.EditIndex = -1
        DataBind()
    End Sub
    Protected Sub Gridview1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
        
        Dim txR, txP, txC, txB, txCount, txtLM, txFM, txMN, txSexC, txPC, txSM As TextBox
     
        Dim row As GridViewRow = GridView1.Rows(e.RowIndex)
        txR = CType(row.Cells(1).Controls(0), TextBox)
        txP = CType(row.Cells(2).Controls(0), TextBox)
        txC = CType(row.Cells(3).Controls(0), TextBox)
        txB = CType(row.Cells(4).Controls(0), TextBox)
        txCount = CType(row.Cells(5).Controls(0), TextBox)
        txPC = CType(row.Cells(6).Controls(0), TextBox)
        txtLM = CType(row.Cells(7).Controls(0), TextBox)
        txFM = CType(row.Cells(8).Controls(0), TextBox)
        txMN = CType(row.Cells(9).Controls(0), TextBox)
        txSM = CType(row.Cells(10).Controls(0), TextBox)
        txSexC = CType(row.Cells(11).Controls(0), TextBox)
      
        
        Dim connection As OleDbConnection
        connection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\emong\Documents\Visual Studio 2008\WebSite3\App_Data/dbLupon.mdb")
        
        
        Dim command As OleDbCommand
        command = New OleDbCommand("UPDATE tblLUPON_C SET REGION_C = @REGION_C, PROVINCE_C = @PROVINCE_C, CITYMUN_C =@CITYMUN_C, BARANGAY_C = @BARANGAY_C, COUNT_C = @COUNT_C, POSITION_C = @POSITION_C,  LAST_M = @LAST_M, FIRST_M = @FIRST_M, MIDDLE_M = @MIDDLE_M, SUFFIX_C = @SUFFIX_C, SEX_C = @SEX_C WHERE COUNT_C =@COUNT_C", connection)
        command.Parameters.AddWithValue("@REGION_C", txR.Text)
        command.Parameters.AddWithValue("@PROVINCE_C", txP.Text)
        command.Parameters.AddWithValue("@CITYMUN_C", txC.Text)
        command.Parameters.AddWithValue("@BARANGAY_C", txB.Text)
        command.Parameters.AddWithValue("@COUNT_C", txCount.Text)
        command.Parameters.AddWithValue("@POSITION_C", txPC.Text)
        command.Parameters.AddWithValue("@LAST_M", txtLM.Text)
        command.Parameters.AddWithValue("@FIRST_M", txFM.Text)
        command.Parameters.AddWithValue("@MIDDLE_M", txMN.Text)
        command.Parameters.AddWithValue("@SUFFIX_M", txSM.Text)
        command.Parameters.AddWithValue("@SEX_C", txSexC.Text)

        'Try
        connection.Open()

        command.ExecuteNonQuery()
        '  Catch ex As Exception
        'MsgBox(ex.ToString)
        ' Finally
        connection.Close()
        
        GridView1.EditIndex = -1
        Call BindGrid()
        'End Try
    End Sub
    
    Sub submit(ByVal sender As Object, ByVal e As EventArgs)
     
        Dim m As AccessDataSource
        Dim mylabel As String
        mylabel = cmbProvince.Text
        Select Case mylabel
            ''''REGION I
            Case "ILOCOS SUR", "PANGASINAN", "LA UNION", "ILOCOS NORTE"
                Select Case mylabel
                    Case "ILOCOS SUR"
                        lblProvince.Text = "29"
                    Case "PANGASINAN"
                        lblProvince.Text = "55"
                    Case "ILOCOS NORTE"
                        lblProvince.Text = "28"
                    Case "LA UNION"
                        lblProvince.Text = "33"
                End Select
                lblRegion.Text = "01"
                lblRegion_M.Text = "REGION I - ILOCOS REGION"
                ''''''''''''''''''''''''''''''''''''''''''''''''''''''
                ''''REGION 2
            Case "BATANES", "CAGAYAN", "ISABELA", "NUEVA VIZCAYA", "QUIRINO"
                Select Case mylabel
                    Case "BATANES"
                        lblProvince.Text = "09"
                    Case "CAGAYAN"
                        lblProvince.Text = "15"
                    Case "ISABELA"
                        lblProvince.Text = "31"
                    Case "NUEVA VIZCAYA"
                        lblProvince.Text = "50"
                    Case "QUIRINO"
                        lblProvince.Text = "57"
                End Select
                lblRegion.Text = "02"
                lblRegion_M.Text = "REGION II - CAGAYAN VALLEY"
                ''''''''''''''''''''''''''''''''''''''''''''''''''''
                ''''REGION 3
            Case "BATAAN", "BULACAN", "NUEVA ECIJA", "PAMPANGA", "TARLAC", "ZAMBALES", "AURORA"
                Select Case mylabel
                    Case "BATAAN"
                        lblProvince.Text = "08"
                    Case "BULACAN"
                        lblProvince.Text = "14"
                    Case "NUEVA ECIJA"
                        lblProvince.Text = "49"
                    Case "PAMPANGA"
                        lblProvince.Text = "54"
                    Case "TARLAC"
                        lblProvince.Text = "69"
                    Case "ZAMBALES"
                        lblProvince.Text = "71"
                    Case "AURORA"
                        lblProvince.Text = "77"
                End Select
                lblRegion.Text = "03"
                lblRegion_M.Text = "REGION III - CENTRAL LUZON"
                ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                ''''REGION 4
            Case "BATANGAS", "CAVITE", "LAGUNA", "QUEZON", "RIZAL"
                Select Case mylabel
                    Case "BATANGAS"
                        lblProvince.Text = "10"
                    Case "CAVITE"
                        lblProvince.Text = "21"
                    Case "LAGUNA"
                        lblProvince.Text = "34"
                    Case "QUEZON"
                        lblProvince.Text = "56"
                    Case "RIZAL"
                        lblProvince.Text = "58"
                End Select
                lblRegion.Text = "04"
                lblRegion_M.Text = "REGION IVA - CALABARZON"
                ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                ''''REGION IVB
            Case "ROMBLON", "PALAWAN", "ORIENTAL MINDORO", "OCCIDENTAL MINDORO", "MARINDUQUE"
                Select Case mylabel
                    Case "ROMBLON"
                        lblProvince.Text = "59"
                    Case "PALAWAN"
                        lblProvince.Text = "53"
                    Case "ORIENTAL MINDORO"
                        lblProvince.Text = "52"
                    Case "OCCIDENTAL MINDORO"
                        lblProvince.Text = "51"
                    Case "MARINDUQUE"
                        lblProvince.Text = "40"
                End Select
                lblRegion.Text = "17"
                lblRegion_M.Text = "REGION IVB - MIMAROPA"
                '''''''''''''''''''''''''''''''''''''''''''''''''
                ''''REGION V
            Case "SORSOGON", "MASBATE", "ALBAY", "CAMARINES SUR", "CAMARINES NORTE", "CATANDUANES"
                Select Case mylabel
                    Case "SORSOGON"
                        lblProvince.Text = "62"
                    Case "MASBATE"
                        lblProvince.Text = "41"
                    Case "ALBAY"
                        lblProvince.Text = "05"
                    Case "CAMARINES SUR"
                        lblProvince.Text = "17"
                    Case "CAMARINES NORTE"
                        lblProvince.Text = "16"
                    Case "CATANDUANES"
                        lblProvince.Text = "20"
                End Select
                lblRegion.Text = "05"
                lblRegion_M.Text = "REGION V - BICOL REGION"
                '''''''''''''''''''''''''''''''''''''''''''''''''
                ''''REGION VI
            Case "NEGROS OCCIDENTAL", "AKLAN", "GUIMARAS", "ILOILO", "CAPIZ", "ANTIQUE"
                Select Case mylabel
                    Case "NEGROS OCCIDENTAL"
                        lblProvince.Text = "45"
                    Case "AKLAN"
                        lblProvince.Text = "04"
                    Case "GUIMARAS"
                        lblProvince.Text = "79"
                    Case "ILOILO"
                        lblProvince.Text = "30"
                    Case "CAPIZ"
                        lblProvince.Text = "19"
                    Case "ANTIQUE"
                        lblProvince.Text = "06"
                End Select
                lblRegion.Text = "06"
                lblRegion_M.Text = "REGION VI - WESTERN VISAYAS"
                '''''''''''''''''''''''''''''''''''''''''''''''''
                ''''REGION VII
            Case "SIQUIJOR", "CEBU", "NEGROS ORIENTAL", "BOHOL"
                Select Case mylabel
                    Case "SIQUIJOR"
                        lblProvince.Text = "61"
                    Case "CEBU"
                        lblProvince.Text = "22"
                    Case "NEGROS ORIENTAL"
                        lblProvince.Text = "46"
                    Case "BOHOL"
                        lblProvince.Text = "12"
                End Select
                lblRegion.Text = "07"
                lblRegion_M.Text = "REGION VII - CENTRAL VISAYAS"
                ''''''''''''''''''''''''''''''''''''''''''''''''''
                ''''REGION VIII
            Case "SOUTHERN LEYTE", "BILIRAN", "SAMAR (WESTERN SAMAR)", "NORTHERN SAMAR", "EASTERN SAMAR", "LEYTE"
                Select Case mylabel
                    Case "SOUTHERN LEYTE"
                        lblProvince.Text = "64"
                    Case "BILIRAN"
                        lblProvince.Text = "78"
                    Case "SAMAR (WESTERN SAMAR)"
                        lblProvince.Text = "60"
                    Case "NORTHERN SAMAR"
                        lblProvince.Text = "48"
                    Case "EASTERN SAMAR"
                        lblProvince.Text = "26"
                    Case "LEYTE"
                        lblProvince.Text = "37"
                End Select
                lblRegion.Text = "08"
                lblRegion_M.Text = "Region VIII - EASTERN VISAYAS"
                ''''''''''''''''''''''''''''''''''''''''''''''''
                ''''REGION IX
            Case "ZAMBOANGA DEL NORTE", "ZAMBOANGA DEL SUR", "ZAMBOANGA SIBUGAY", "CITY OF ISABELA (Not a Province)"
                Select Case mylabel
                    Case "ZAMBOANGA DEL NORTE"
                        lblProvince.Text = "72"
                    Case "ZAMBOANGA DEL SUR"
                        lblProvince.Text = "73"
                    Case "ZAMBOANGA SIBUGAY"
                        lblProvince.Text = "83"
                    Case "CITY OF ISABELA (Not a Province)"
                        lblProvince.Text = "97"
                End Select
                lblRegion.Text = "09"
                lblRegion_M.Text = "REGION IX - ZAMBOANGA PENINSULA"
                ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                ''''REGION X
            Case "BUKIDNON", "MISAMIS ORIENTAL", "CAMIGUIN", "MISAMIS OCCIDENTAL", "LANAO DEL NORTE"
                Select Case mylabel
                    Case "BUKIDNON"
                        lblProvince.Text = "13"
                    Case "MISAMIS ORIENTAL"
                        lblProvince.Text = "43"
                    Case "CAMIGUIN"
                        lblProvince.Text = "18"
                    Case "MISAMIS OCCIDENTAL"
                        lblProvince.Text = "42"
                    Case "LANAO DEL NORTE"
                        lblProvince.Text = "35"
                End Select
                lblRegion.Text = "10"
                lblRegion_M.Text = "REGION X - NORTHERN MINDANAO"
                ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                ''''REGION XI
            Case "DAVAO DEL NORTE", "DAVAO DEL SUR", "DAVAO ORIENTAL", "COMPOSTELA VALLEY"
                Select Case mylabel
                    Case "DAVAO DEL NORTE"
                        lblProvince.Text = "23"
                    Case "DAVAO DEL SUR"
                        lblProvince.Text = "24"
                    Case "DAVAO ORIENTAL"
                        lblProvince.Text = "25"
                    Case "COMPOSTELA VALLEY"
                        lblProvince.Text = "82"
                End Select
                lblRegion.Text = "11"
                lblRegion_M.Text = "REGION XI - DAVAO REGION"
                ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                ''''REGION XII
            Case "COTOBATO CITY (Not a Province)", "COTABATO (NORTH COTABATO)", "SOUTH COTABATO", "SULTAN KUDARAT", "SARANGANI"
                Select Case mylabel
                    Case "COTABATO CITY (Not a Province)" '
                        lblProvince.Text = "98"
                    Case "COTABATO (NORTH COTABATO)"
                        lblProvince.Text = "47"
                    Case "SOUTH COTABATO"
                        lblProvince.Text = "63"
                    Case "SULTAN KUDARAT"
                        lblProvince.Text = "65"
                    Case "SARANGANI"
                        lblProvince.Text = "80"
                End Select
                lblRegion.Text = "12"
                lblRegion_M.Text = "REGION XII - SOCCSKSARGEN"
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                '''''''''NCR MISSING.....
            Case "METRO MANILA"
                lblProvince.Text = "99"
                lblRegion.Text = "13"
                lblRegion_M.Text = "National Capital Region (NCR)"
                ''''REGION XIV
            Case "IFUGAO", "APAYAO", "KALINGA", "BENGUET", "MOUNTAIN PROVINCE", "ABRA"
                Select Case mylabel
                    Case "IFUGAO"
                        lblProvince.Text = "27"
                    Case "APAYAO"
                        lblProvince.Text = "81"
                    Case "KALINGA"
                        lblProvince.Text = "32"
                    Case "BENGUET"
                        lblProvince.Text = "11"
                    Case "MOUNTAIN PROVINCE"
                        lblProvince.Text = "44"
                    Case "ABRA"
                        lblProvince.Text = "01"
                End Select
                lblRegion.Text = "14"
                lblRegion_M.Text = "CORDILLERA ADMINISTRATIVE REGION"
                ''''''''''''''''''''''''''''''''''''''''
                ''''REGION XV
            Case "LANAO DEL SUR", "TAWI-TAWI", "MAGUINDANAO", "BASILAN", "SULU"
                Select Case mylabel
                    Case "LANAO DEL SUR"
                        lblProvince.Text = "36"
                    Case "TAWI-TAWI"
                        lblProvince.Text = "70"
                    Case "MAGUINDANAO"
                        lblProvince.Text = "38"
                    Case "BASILAN"
                        lblProvince.Text = "07"
                    Case "SULU"
                        lblProvince.Text = "66"
                End Select
                lblRegion.Text = "15"
                lblRegion_M.Text = "AUTONOMOUS REGION IN MUSLIM MINDANAO"
                '''''''''''''''''''''''''''''''''''''''''''''''''
                ''''REGION XVI
            Case "DINAGAT ISLANDS", "SURIGAO DEL SUR", "SURIGAO DEL NORTE", "AGUSAN DEL SUR", "AGUSAN DEL NORTE"
                Select Case mylabel
                    Case "DINAGAT ISLANDS"
                        lblProvince.Text = "85"
                    Case "SURIGAO DEL SUR"
                        lblProvince.Text = "68"
                    Case "SURIGAO DEL NORTE"
                        lblProvince.Text = "67"
                    Case "AGUSAN DEL SUR"
                        lblProvince.Text = "03"
                    Case "AGUSAN DEL NORTE"
                        lblProvince.Text = "02"
                End Select
                lblRegion.Text = "16"
                lblRegion_M.Text = "REGION XIII - CARAGA"
                '''''''''''''''''''''''''''''''''''''''''''''
            Case Else
                lblRegion.Text = "00"
                lblRegion_M.Text = "No record found"
        End Select
        m = adocity
        With m
            .DataFile = "~/App_Data/dbLupon.mdb"
            .SelectCommand = "SELECT * FROM [tblCITYMUN_C] WHERE [CITYMUN_M] IS NOT NULL and([PROVINCE_C] = '" & lblProvince.Text & "')"
        End With
        Call BindGrid()
    End Sub
    
    
    
    
    
</script>

<html>
<head id="Head1" runat="server">
    <style type="text/css">
        .sample
        {
        	background:url(Image/l1.jpg);
        	background-repeat:no-repeat;
        	height:auto;
        	width:auto;
        	}
    </style>
    <title>Lupong Tagapamayapa</title>
</head>
<body>
    <form id="form1" runat="server">
    <div class="sample">
    <br />
    <br />
    <br />
    <br />
    <br />
        <br />
        <br />
        <br />
        <br />
    <br />
    
    <asp:Label ID="Label1" runat="server" Text="Region :" 
        Font-Names="Century Gothic"></asp:Label>
    &nbsp;&nbsp;&nbsp;
    <asp:Label ID="lblRegion" runat="server" Text="14"></asp:Label>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Label ID="lblRegion_M" runat="server" 
        Text="CORDILLERA ADMINISTRATIVE REGION" Font-Names="Century Gothic"></asp:Label>
    <br />
    <br />
    <asp:Label ID="Label2" runat="server" Text="Province :" 
        Font-Names="Century Gothic"></asp:Label>
    &nbsp;&nbsp;&nbsp;
    <asp:Label ID="lblProvince" runat="server" Text="01"></asp:Label>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:DropDownList ID="cmbProvince" runat="server" Height="16px" Width="291px" DataSourceID="adoProvince"
        AutoPostBack="True" OnSelectedIndexChanged="submit" DataTextField="PROVINCE_M"
        DataValueField="PROVINCE_M" Font-Names="Century Gothic">
      
    </asp:DropDownList>
    <asp:AccessDataSource ID="adoProvince" runat="server" DataFile="~/App_Data/dbLupon.mdb"
        SelectCommand="SELECT [PROVINCE_M] FROM [tblPROVINCE_C] WHERE ([PROVINCE_M] IS NOT NULL) ORDER BY [PROVINCE_M]">
    </asp:AccessDataSource>
    <br />
    <br />
    <asp:Label ID="Label3" runat="server" Text="City/Municipality :" 
        Font-Names="Century Gothic"></asp:Label>
    &nbsp;&nbsp;&nbsp;
    <asp:DropDownList ID="cmbCity" runat="server" Height="20px" Width="291px" AutoPostBack="True"
        DataSourceID="adocity" DataTextField="CITYMUN_M"
        DataValueField="CITYMUN_C" Font-Names="Century Gothic">
    </asp:DropDownList>
    <br />
    <asp:AccessDataSource ID="adocity" runat="server" DataFile="~/App_Data/dbLupon.mdb"
        SelectCommand="SELECT * FROM [tblCITYMUN_C] WHERE (([CITYMUN_M] IS NOT NULL) AND ([PROVINCE_C] = ?)) ORDER BY [CITYMUN_M]">
        <SelectParameters>
            <asp:ControlParameter ControlID="lblProvince" Name="PROVINCE_C" 
                PropertyName="Text" Type="String" />
        </SelectParameters>
    </asp:AccessDataSource>
        
    <asp:Label ID="lblCityMun" runat="server" Text="02" Visible="False"></asp:Label>
    <br />
    <asp:Label ID="Label4" runat="server" Text="Barangay :" 
        Font-Names="Century Gothic"></asp:Label>
    &nbsp;&nbsp;&nbsp;
    <asp:Label ID="lblBarangay_C" runat="server" Text="01" Visible="False"></asp:Label>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:DropDownList ID="cmbBrgy" runat="server" Height="18px" Width="291px" DataSourceID="adobarangay"
        DataTextField="BARANGAY_M" AutoPostBack="True" DataValueField="BARANGAY_C" 
        Font-Names="Century Gothic">
    </asp:DropDownList>
    <asp:AccessDataSource ID="adobarangay" runat="server" DataFile="~/App_Data/dbLupon.mdb"
        SelectCommand="SELECT * FROM [tblBARANGAY_C] WHERE (([BARANGAY_M] IS NOT NULL) AND ([CITYMUN_C] = ?) AND ([PROVINCE_C] = ?)) ORDER BY [BARANGAY_M]">
        <SelectParameters>
            <asp:ControlParameter ControlID="cmbCity" Name="CITYMUN_C" PropertyName="SelectedValue"
                Type="String" />
            <asp:ControlParameter ControlID="lblProvince" Name="PROVINCE_C" 
                PropertyName="Text" Type="String" />
        </SelectParameters>
    </asp:AccessDataSource>
    <br />
        <asp:GridView ID="GridView1" runat="server" OnRowUpdating="Gridview1_RowUpdating"
                OnRowCancelingEdit = "Gridview1_RowCancelingEdit"
                OnRowEditing= "GridView1_RowEditing" AutoGenerateEditButton="True" >
    </asp:GridView>
    </div>
    </form>
</body>
</html>

hello . :D

i'm having a problem regarding the update on gridview...

the process is that I will select 1st three dropdown and filter those selection.

REGION : CAR
PROVINCE : <dropdown>
CITY : <dropdown>
BARANGAY : <dropdown>

AND THEN the members of those filter will show by means of gridview.. then In gridview I can edit and update records..

the problem is that the record is not updating :( please help me. please.

and another one, how can I add new record in the gridview.

THANKS MUCH!

Recommended Answers

You are using too much Wizards that is why your code confuses you. Look at what Sheo did in his article

http://www.dotnetfunda.com/articles/article18.aspx

Jump to Post

All 2 Replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.