ASP.NET: session in a dropdownlist only works in one panel.

mush 181 Reputation points
2022-05-30T05:24:15.273+00:00

I'm using a dropdown list where when selected it will filter data based on the selected branch in two panels. the problem is it will filter only one panel and ignore the other even though I added the session in both panels.

this is my code:

aspx code:

   <%@ Page Title="" Language="VB" MasterPageFile="~/En/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>  
      
  
  
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">  
        <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" />  
     <link rel="stylesheet" href="plugins/DataTablesNew/DataTables-1.10.16/css/dataTables.bootstrap.min.css"/>  
     <link rel="stylesheet" href="plugins/DataTablesNew/Responsive-2.2.1/css/responsive.bootstrap.min.css" />  
    <link rel="stylesheet" href="dist/css/StyleSheet.css" />  
    <link rel="stylesheet" href="dist/css/waitMe.css"/>  
    <link rel="stylesheet" href="bootstrap/css/bootstrap-select.css"/>  
    <link rel="Stylesheet" href="plugins/jQueryUI/jquery-ui.css" />  
  
    <script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>  
     <script src="plugins/DataTablesNew/DataTables-1.10.16/js/jquery.dataTables.min.js"></script>  
     <script src="plugins/DataTablesNew/DataTables-1.10.16/js/dataTables.bootstrap.min.js"></script>  
    <script src="plugins/DataTablesNew/Responsive-2.2.1/js/dataTables.responsive.min.js"></script>  
    <script src="plugins/DataTablesNew/Responsive-2.2.1/js/responsive.bootstrap.min.js"></script>  
    <script src="bootstrap/js/bootstrap-filestyle.min.js"></script>  
    <script src="dist/js/waitMe.js"></script>  
    <script src="bootstrap/js/bootstrap-select.js"></script>  
    <script src="plugins/jQueryUI/jquery-ui_1.0.8.js"></script>  
     <script src="plugins/chartjs/Chart.min.js"></script>  
  
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>  
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>  
    <script type="text/javascript">  
  
  
        google.charts.load('current', { 'packages': ['corechart'] });  
        google.charts.setOnLoadCallback(drawChart);  
        google.charts.setOnLoadCallback(drawChart1);  
        google.charts.setOnLoadCallback(drawChart2);  
        google.setOnLoadCallback(drawBarChart);  
        google.setOnLoadCallback(drawChartt);  
        google.setOnLoadCallback(drawCharttt);  
         
         
      
         
         
        function drawChart() {  
            var options = {  
                title: 'Staff by Departments',  
                is3D: true,  
            };  
            $.ajax({  
                type: "POST",  
                type: "POST",  
                url: "Default.aspx/GetChartDataByDept",  
                data: '{}',  
                contentType: "application/json; charset=utf-8",  
                dataType: "json",  
                success: function (r) {  
                    var data = google.visualization.arrayToDataTable(r.d);  
                    var chart = new google.visualization.PieChart(document.getElementById('piechart'));  
                    chart.draw(data, options);  
                }  
            });  
  
            //var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));  
            //chart.draw(data, options);  
        }  
        function drawChart1() {  
            var options = {  
                title: 'Staff by Nationality',  
                is3D: true,  
            };  
            $.ajax({  
                type: "POST",  
                url: "Default.aspx/GetChartDataByNationality",  
                data: '{}',  
                contentType: "application/json; charset=utf-8",  
                dataType: "json",  
                success: function (r) {  
                    var data = google.visualization.arrayToDataTable(r.d);  
                    //var chart = new google.visualization.ColumnChart($("#chart")[0]);  
                    var chart = new google.visualization.PieChart(document.getElementById('piechart1'));  
                    chart.draw(data, options);  
                }  
            });  
            //var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));  
            //chart.draw(data, options);  
        }  
          
        function drawChart2() {  
            var options = {  
                title: 'Staff by Employer',  
                is3D: true,  
            };  
            $.ajax({  
                type: "POST",  
                url: "Default.aspx/GetChartDataByEmployer",  
                data: '{}',  
                contentType: "application/json; charset=utf-8",  
                dataType: "json",  
                success: function (r) {  
                    var data = google.visualization.arrayToDataTable(r.d);  
                    //var chart = new google.visualization.ColumnChart($("#chart")[0]);  
                    var chart = new google.visualization.PieChart(document.getElementById('piechart2'));  
                    chart.draw(data, options);  
                }  
            });  
            //var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));  
            //chart.draw(data, options);  
        }  
  
  
        function drawBarChart() {  
            var options = {  
                title: 'Staff by Designation',  
                is3D: true,  
            };  
            $.ajax({  
                type: "POST",  
                url: "Default.aspx/GetChartDataByDesignation",  
                data: '{}',  
                contentType: "application/json; charset=utf-8",  
                dataType: "json",  
                success: function (r) {  
                    var data = google.visualization.arrayToDataTable(r.d);  
                    //var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));  
                    var chart = new google.visualization.ColumnChart(document.getElementById('AreaChart'));  
                    chart.draw(data, options);  
                },  
                failure: function (r) {  
                    alert(r.d);  
                },  
                error: function (r) {  
                    alert(r.d);  
                }  
            });  
        }  
        function drawChartt() {  
            var options = {  
                title: 'Staff by Status',  
                pieHole: 0.5  
            };  
            $.ajax({  
                type: "POST",  
                url: "Default.aspx/GetChartData",  
                data: '{}',  
                contentType: "application/json; charset=utf-8",  
                dataType: "json",  
                success: function (r) {  
                    var data = google.visualization.arrayToDataTable(r.d);  
                    var chart = new google.visualization.PieChart($("#chartt")[0]);  
                    chart.draw(data, options);  
                },  
                failure: function (r) {  
                    alert(r.d);  
                },  
                error: function (r) {  
                    alert(r.d);  
                }  
            });  
        }  
        function drawCharttt() {  
            var options = {  
                title: 'Staff by Gender',  
               
                bar: { groupWidth: "95%" },  
                legend: { position: "none" },  
                isStacked: true  
            };  
            $.ajax({  
                type: "POST",  
                url: "Default.aspx/GetChartDataByGender",  
                data: '{}',  
                contentType: "application/json; charset=utf-8",  
                dataType: "json",  
                success: function (r) {  
                    var data = google.visualization.arrayToDataTable(r.d);  
                    var chart = new google.visualization.BarChart($("#charttt")[0]);  
                    chart.draw(data, options);  
                },  
                failure: function (r) {  
                    alert(r.d);  
                },  
                error: function (r) {  
                    alert(r.d);  
                }  
            });  
        }  
        //function drawChart3() {  
        //    var options = {  
        //        title: 'Staff by Gender',  
        //        is3D: true,  
        //    };  
        //    $.ajax({  
        //        type: "POST",  
        //        url: "Default.aspx/GetChartDataByGender",  
        //        data: '{}',  
        //        contentType: "application/json; charset=utf-8",  
        //        dataType: "json",  
        //        success: function (r) {  
        //            var data = google.visualization.arrayToDataTable(r.d);  
        //            //var chart = new google.visualization.ColumnChart($("#chart")[0]);  
        //            var chart = new google.visualization.PieChart(document.getElementById('piechart3'));  
        //            chart.draw(data, options);  
        //        }  
        //    });  
        //    //var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));  
        //    //chart.draw(data, options);  
        //}  
         
  
  
    </script>  
  
    <style>  
        .divtop{  
            margin-top:50px;  
        }  
        @media (max-width:960) {  
            .divtop {  
                margin-top:200px;  
                background-color:antiquewhite;  
            }  
        }  
        .auto-style1 {  
            font-size: large;  
        }  
    </style>  
      
     
</asp:Content>  
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">  
       <!-- Content Header (Page header) -->  
    <%--<div class="divtop"></div>--%>  
          
          
       <div id="conte" runat="server">  
           <section class="content">  
           <div class="row">  
            <div class="col-md-12">  
              <!-- Box Comment -->  
              <div class="box box-widget">  
                <div class="box-header with-border">  
                                  
                </div><!-- /.box-header -->  
                <div class="box-body">  
                 <div class="row" id="div2" runat="server">  
            <div class="col-lg-3 col-xs-6">  
              <!-- small box -->  
                <a href="#" style="text-decoration:none">  
              <div class="small-box bg-aqua-gradient">  
                <div class="inner">  
                  <h3>  
                      <asp:Label ID="lblBranchesCount" runat="server" Text=""></asp:Label></h3>  
                  <p>Branches</p>  
                </div>  
                <div class="icon">  
                  <i class="fa fa-university"></i>  
                </div>  
                <div class="small-box-footer">  
                     
                </div>  
              </div>  
                    </a>  
            </div><!-- ./col -->  
            <div class="col-lg-3 col-xs-6">  
              <!-- small box -->  
                <a href="#" style="text-decoration:none">  
              <div class="small-box bg-yellow-gradient">  
                <div class="inner">  
                  <h3><asp:Label ID="lblStaffCount" runat="server" Text=""></asp:Label></h3>  
                  <p>Staff</p>  
                </div>  
                <div class="icon">  
                  <i class="fa fa-group"></i>  
                </div>  
                <div class="small-box-footer">  
                     
                </div>  
              </div>  
                    </a>  
            </div>  
            <div class="col-lg-3 col-xs-6">  
              <!-- small box -->  
                <a href="#" style="text-decoration:none">  
              <div class="small-box bg-blue-gradient">  
                <div class="inner">  
                  <h3><asp:Label ID="lblDepartment" runat="server" Text="0"></asp:Label></h3>  
                  <p>Departments</p>  
                </div>  
                <div class="icon">  
                  <i class="fa fa-group fa-university"></i>  
                </div>  
                <div class="small-box-footer">  
                     
                </div>  
              </div>  
                    </a>  
            </div>  
  
            <div class="col-lg-3 col-xs-6">  
              <!-- small box -->  
                <a href="#" style="text-decoration:none">  
              <div class="small-box bg-blue-gradient">  
                <div class="inner">  
                  <h3><asp:Label ID="lblDesignations" runat="server" Text="0"></asp:Label></h3>  
                  <p>Designations</p>  
                </div>  
                <div class="icon">  
                  <i class="fa fa-group fa-group"></i>  
                </div>  
                <div class="small-box-footer">  
                     
                </div>  
              </div>  
                    </a>  
            </div>  
  
                
          </div>  
                    <div class="row hidden">  
                        <div class="col-lg-5">  
                            <div class="box box-default">                 
                             <div class="box-header">  
                                  <h3 class="box-title">Employee by Nationality</h3>  
                                   <div class="box-tools pull-right">  
                      
                  </div>  
                </div>  
                                                            
<div class="box-body">                 <canvas id="myChart" style="width:100%;max-width:600px"></canvas>  
                  
</div><!-- /.box-body -->                
</div>  
                        </div>  
                    </div>  
  
                      
                 
                          
               </div>  
                  
                 
              </div><!-- /.box -->  
            </div><!-- /.col -->  
              
                 
            
</div>  
<%--               <asp:Panel ID="Panel1" runat="server">--%>  
            <div class="row">  
            <div class="col-md-12">  
              <!-- Box Comment -->  
              <div class="box box-widget">  
                <div class="box-header with-border">  
                                  
                </div><!-- /.box-header -->  
                <div class="box-body">  
            <div>  
                                                  <strong>  
                                                      <%--<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>--%>                                 <asp:Label ID="Label1" runat="server" Text="Filter by Branch:"></asp:Label>     </strong>     <asp:DropDownList ID="ddlBranches" OnSelectedIndexChanged="ddlBranches_SelectedIndexChanged" AutoPostBack="true" runat="server" Height="28px" Width="79px"></asp:DropDownList>  
            </div>  
                    <strong>  
                    <asp:Panel ID="Panel2" runat="server" BorderColor="Maroon" BorderStyle="Groove" CssClass="auto-style1">There is Currently No Data Available For This Branch...</asp:Panel>  
                    </strong>  
                    <asp:Panel ID="Panel1" runat="server">  
                      
                          <div id="div1" class="row" runat="server">  
                              <div>  
                                   
                                      <%--<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>--%>  
  
                              </div>  
                        <div class="col-lg-4">  
                                       
                               
                    
                                 
                <div id="piechart" ></div>  
                  
      
  
                        </div>  
                                  <div class="col-lg-4">  
                                       
                               
                    
                                 
                <div id="piechart1" ></div>  
                  
      
  
                        </div>  
                                        <div class="col-lg-4">  
                                       
                               
                    
                                 
                <div id="piechart2" ></div>  
                  
      
  
                        </div>  
                                 <div class="col-lg-4">  
                                       
                               
                  <div class="reaChart"></div>  
                                 
                <div id="chartt"></div>  
                  
      
  
                        </div>  
                                 
                              <div class="col-lg-4">  
                                       
                               
                    
                                 
                <div id="AreaChart"></div>  
                  
      
  
                        </div>  
                                 <div class="col-lg-4">  
                            <div id="charttt">  
</div>      </div>    
                    </div>  
                 
                      </asp:Panel>  
                        
               </div>  
             
              </div><!-- /.box -->  
            </div><!-- /.col -->  
              
                 
            
</div>  
         </section>  
       </div>  
      
      
 <script>  
     var xValues = ["Italy", "France", "Spain", "USA", "Argentina"];  
     var yValues = [55, 49, 44, 24, 15];  
     var barColors = [  
         "#b91d47",  
         "#00aba9",  
         "#2b5797",  
         "#e8c3b9",  
         "#1e7145"  
     ];  
  
     new Chart("myChart", {  
         type: "doughnut",  
         data: {  
             labels: xValues,  
             datasets: [{  
                 backgroundColor: barColors,  
                 data: yValues  
             }]  
         },  
         options: {  
             title: {  
                 display: false,  
                 text: "World Wide Wine Production 2018"  
             },  
             plugins: {  
                 datalabels: {  
                     display: false  
                 }  
             }  
         }  
     });  
 </script>  
</asp:Content>  

vb.net code:

Imports System.Data.SqlClient  
Imports System.Data  
Imports System.Web.Services  
  
Partial Class _Default  
    Inherits System.Web.UI.Page  
    Dim Sql As String  
    Dim nqcmd As New SqlCommand  
    Dim ConnString As String = ConfigurationManager.ConnectionStrings("dbConn").ConnectionString  
    Dim cn As SqlConnection = New SqlConnection(ConnString)  
    Dim da As SqlDataAdapter = New SqlDataAdapter  
    Dim dt As New DataTable  
    Dim branch As Int32  

Private Sub _Default_Load(sender As Object, e As EventArgs) Handles Me.Load  
    Authentication.IsValidUserRedirect()  
    If Not Page.IsPostBack Then  
        lblBranchesCount.Text = GetBranchesCount()  
        lblStaffCount.Text = GetStaff()  
        lblDepartment.Text = GetDepart()  
        lblDesignations.Text = GetDesignations()  
        Panel2.Visible = False  

        ' to hide the dropdownlist if the user type is not a super admin or  head or  HR Main Branch  

        Dim dt1 As DataTable = New DataTable()  
        Dim constr1 As String = ConfigurationManager.ConnectionStrings("dbConn").ConnectionString  
        Using con As SqlConnection = New SqlConnection(ConnString)  
            Using cmdd As SqlCommand = New SqlCommand("SELECT userTypeId FROM tblUserType ", con)  
                cmdd.CommandType = CommandType.Text  
                Dim da As SqlDataAdapter = New SqlDataAdapter(cmdd)  
                da.Fill(dt1)  
                If dt1.Rows.Count > 0 Then  
                    If HttpContext.Current.Session("EmpTypeID") = 4 Then  
                        ddlBranches.Visible = False  
                        Label1.Visible = False  

                    End If  

                End If  
            End Using  
        End Using  



        ' to store the branch id value in a session  

        Dim dt2 As DataTable = New DataTable()  
        Dim constr2 As String = ConfigurationManager.ConnectionStrings("dbConn").ConnectionString  
        Using con As SqlConnection = New SqlConnection(ConnString)  
            Using cmddd As SqlCommand = New SqlCommand("SELECT unibranchid FROM tblUniversityBranches ", con)  
                cmddd.CommandType = CommandType.Text  
                Dim da As SqlDataAdapter = New SqlDataAdapter(cmddd)  
                da.Fill(dt1)  
                If dt2.Rows.Count <> 0 Then  
                    HttpContext.Current.Session("UnBarnchID") = "unibranchid"  

                End If  

            End Using  
        End Using  

        ' to bind the dropdownlist and create a session for it  

        Dim dt As DataTable = New DataTable()  
        Dim constr As String = ConfigurationManager.ConnectionStrings("dbConn").ConnectionString  
        Using con As SqlConnection = New SqlConnection(ConnString)  
            Using cmd As SqlCommand = New SqlCommand("SELECT * FROM tblUniversityBranches", con)  
                cmd.CommandType = CommandType.Text  
                Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)  
                da.Fill(dt)  
            End Using  
        End Using  
        'Dim iUnBarnchID As Integer = -1  
        'HttpContext.Current.Session("UnBarnchID") = iUnBarnchID  
        ddlBranches.Items.Clear()  
        ddlBranches.Items.Insert(0, New ListItem("--Select--", "0"))  
        ddlBranches.AppendDataBoundItems = True  
        ddlBranches.DataTextField = "UniBranchNameEn"  
        ddlBranches.DataValueField = "UniBranchNameEn"  
        ddlBranches.DataSource = dt  
        ddlBranches.DataBind()  
        HttpContext.Current.Session("dbr") = "test"  
        'HttpContext.Current.Session("ubid") = "UniBranchID"  
        'System.Web.HttpContext.Current.Session("dbr") = ddlBranches.SelectedValue  

    End If  
End Sub  
Public Shared Function GetBranchesCount() As String  
    If (HttpContext.Current.Session("EmpTypeID")) = 4 Then  
        'Dim iUnBarnchID As Integer = -1  
        'HttpContext.Current.Session("UnBarnchID") = iUnBarnchID  
        Dim Sql As String  

        Dim nqcmd As New SqlCommand  
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("dbConn").ConnectionString  
        Dim cn As SqlConnection = New SqlConnection(ConnString)  
        Dim da As SqlDataAdapter = New SqlDataAdapter  
        Dim dt As New DataTable  
        Dim iBranchesCount As String = "0"  
        If cn.State = ConnectionState.Closed Then  
            cn.Open()  
        End If  
        Sql = "select Count(*) as BranchesCount From tblUniversityBranches where unibranchid='" + Convert.ToString(HttpContext.Current.Session("UnBarnchID").ToString) + "' and Status = 1"  
        da.SelectCommand = New SqlCommand(Sql, cn)  
        dt.Clear()  
        da.Fill(dt)  
        If dt.Rows.Count <> 0 Then  
            If Not IsDBNull(dt.Rows(0)("BranchesCount")) Then  
                iBranchesCount = dt.Rows(0)("BranchesCount")  
            End If  
            Return iBranchesCount  
        End If  
        Return iBranchesCount  
        If cn.State = ConnectionState.Open Then  
            cn.Close()  
        End If  

    Else  
        Dim Sql As String  
        Dim nqcmd As New SqlCommand  
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("dbConn").ConnectionString  
        Dim cn As SqlConnection = New SqlConnection(ConnString)  
        Dim da As SqlDataAdapter = New SqlDataAdapter  
        Dim dt As New DataTable  
        Dim iBranchesCount As String = "0"  
        If cn.State = ConnectionState.Closed Then  
            cn.Open()  
        End If  
        Sql = "select Count(*) as BranchesCount From tblUniversityBranches where univbranchid='" + Convert.ToString(HttpContext.Current.Session("dbr").ToString) + "'"  
        Sql += " where Status = 1"  
        da.SelectCommand = New SqlCommand(Sql, cn)  
        dt.Clear()  
        da.Fill(dt)  
        If dt.Rows.Count <> 0 Then  
            If Not IsDBNull(dt.Rows(0)("BranchesCount")) Then  
                iBranchesCount = dt.Rows(0)("BranchesCount")  
            End If  
            Return iBranchesCount  
        End If  
        Return iBranchesCount  
        If cn.State = ConnectionState.Open Then  
            cn.Close()  
        End If  
    End If  


End Function  
Public Shared Function GetStaff() As String  
    If (HttpContext.Current.Session("EmpTypeID")) = 4 Then  


        Dim Sql As String  
        Dim nqcmd As New SqlCommand  
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("dbConn").ConnectionString  
        Dim cn As SqlConnection = New SqlConnection(ConnString)  
        Dim da As SqlDataAdapter = New SqlDataAdapter  
        Dim dt As New DataTable  
        Dim iStaffCount As String = "0"  
        If cn.State = ConnectionState.Closed Then  
            cn.Open()  
        End If  
        Sql = "select Count(*) as StaffCount From tblEmployee "  
        Sql += "where univbranchid='" + Convert.ToString(HttpContext.Current.Session("UnBarnchID").ToString) + "'"  
        'Sql += " Where Status = 1"  
        da.SelectCommand = New SqlCommand(Sql, cn)  
        dt.Clear()  
        da.Fill(dt)  
        If dt.Rows.Count <> 0 Then  
            If Not IsDBNull(dt.Rows(0)("StaffCount")) Then  
                iStaffCount = dt.Rows(0)("StaffCount")  
            End If  
            Return iStaffCount  
        End If  
        Return iStaffCount  
        If cn.State = ConnectionState.Open Then  
            cn.Close()  
        End If  
    Else  

        Dim Sql As String  
        Dim nqcmd As New SqlCommand  
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("dbConn").ConnectionString  
        Dim cn As SqlConnection = New SqlConnection(ConnString)  
        Dim da As SqlDataAdapter = New SqlDataAdapter  
        Dim dt As New DataTable  
        Dim iStaffCount As String = "0"  
        If cn.State = ConnectionState.Closed Then  
            cn.Open()  
        End If  
        Sql = "select Count(*) as StaffCount From tblEmployee where univbranchid='" + Convert.ToString(HttpContext.Current.Session("dbr").ToString) + "'"  
        'Sql += " Where Status = 1"  
        da.SelectCommand = New SqlCommand(Sql, cn)  
        dt.Clear()  
        da.Fill(dt)  
        If dt.Rows.Count <> 0 Then  
            If Not IsDBNull(dt.Rows(0)("StaffCount")) Then  
                iStaffCount = dt.Rows(0)("StaffCount")  
            End If  
            Return iStaffCount  
        End If  
        Return iStaffCount  
        If cn.State = ConnectionState.Open Then  
            cn.Close()  
        End If  
    End If  
End Function  
Public Shared Function GetDepart() As String  
    If (HttpContext.Current.Session("EmpTypeID")) = 4 Then  
        Dim Sql As String  
        Dim nqcmd As New SqlCommand  
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("dbConn").ConnectionString  
        Dim cn As SqlConnection = New SqlConnection(ConnString)  
        Dim da As SqlDataAdapter = New SqlDataAdapter  
        Dim dt As New DataTable  
        Dim iDeptCount As String = "0"  
        If cn.State = ConnectionState.Closed Then  
            cn.Open()  
        End If  
        Sql = "select Count(*) as DeptCount From tblDepartments inner join tblUniBranch_X_Department on tblUniBranch_X_Department.deptid=tblDepartments.deptid  where unibranchid='" + Convert.ToString(HttpContext.Current.Session("UnBarnchID").ToString) + "' and tblDepartments.Status = 1"  
        da.SelectCommand = New SqlCommand(Sql, cn)  
        dt.Clear()  
        da.Fill(dt)  
        If dt.Rows.Count <> 0 Then  
            If Not IsDBNull(dt.Rows(0)("DeptCount")) Then  
                iDeptCount = dt.Rows(0)("DeptCount")  
            End If  
            Return iDeptCount  
        End If  
    Else  

        Dim Sql As String  
        Dim nqcmd As New SqlCommand  
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("dbConn").ConnectionString  
        Dim cn As SqlConnection = New SqlConnection(ConnString)  
        Dim da As SqlDataAdapter = New SqlDataAdapter  
        Dim dt As New DataTable  
        Dim iDeptCount As String = "0"  
        If cn.State = ConnectionState.Closed Then  
            cn.Open()  
        End If  
        Sql = "Select Count(*) As DeptCount From tblDepartments where univbranchid='" + Convert.ToString(HttpContext.Current.Session("dbr").ToString) + "' "  
        Sql += " where Status = 1"  
        da.SelectCommand = New SqlCommand(Sql, cn)  
        dt.Clear()  
        da.Fill(dt)  
        If dt.Rows.Count <> 0 Then  
            If Not IsDBNull(dt.Rows(0)("DeptCount")) Then  
                iDeptCount = dt.Rows(0)("DeptCount")  
            End If  
            Return iDeptCount  
        End If  

        Return iDeptCount  
        If cn.State = ConnectionState.Open Then  
            cn.Close()  
        End If  
        End if  
End Function  
Public Shared Function GetDesignations() As String  
    If (HttpContext.Current.Session("EmpTypeID")) = 4 Then  

        Dim Sql As String  
        Dim nqcmd As New SqlCommand  
        Dim ConnStrin
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,273 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 25,716 Reputation points Microsoft Vendor
    2022-05-30T08:06:45.057+00:00

    Hi @mush ,
    I checked your code and found nothing in Panel2 so it doesn't work.
    You need to put the code for the top card into Panel2.
    EDIT

     HttpContext.Current.Session("dbr") = "test"  
     HttpContext.Current.Session("dbr") = ddlBranches.SelectedIndex  
    

    Duplicate code settings for HttpContext.Current.Session("dbr")

    There is another problem. The following code responds when the page is loaded for the first time, but methods such as GetBranchesCount() contain the session of SelectedIndexChanged. It is recommended to put the judgment in SelectedIndexChanged.

    If Not Page.IsPostBack Then  
             lblBranchesCount.Text = GetBranchesCount()  
             lblStaffCount.Text = GetStaff()  
             lblDepartment.Text = GetDepart()  
             lblDesignations.Text = GetDesignations()  
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Olaf Helper 40,901 Reputation points
    2022-05-30T09:59:52.477+00:00

    Sql = "select Count(*) as BranchesCount From tblUniversityBranches where univbranchid='" + Convert.ToString(HttpContext.Current.Session("dbr").ToString) + "'"
    Sql += " where Status = 1"

    Just a note on line 130+131; you have two WHERE clause in the SQL statement, that will fail with a syntax error.