Bound DropDownList: What is the best way?

Discussion in 'ASP .Net Web Controls' started by Anthony Sullivan, Dec 22, 2003.

  1. I have a DropDownList that I am binding to an array that has a list of
    Active Directory Groups in it. I have a couple of problems that I am
    experiencing and I'm wondering if someone could help.

    First, We have about 155 groups in our AD and pulling that entire list takes
    about 10 seconds on our network. I expect this to improve slightly when we
    move to a production environment but not enough for my liking. Currently the
    code used to populate this DropDownList control is called from the
    Page_Load. What is the best way to cache this information so that it isn't
    loaded everytime the page loads.

    Second, once the DropDownList is populated everything works fine until the
    user submits the form. For some reason the value is not being passed or
    retained upon submission. When I try to reference the object serverside it
    thinks that the object selected was the first item in the list regardless of
    what was actually selected. I have another scenario where the options are
    hardcoded and this doesn't not happen. Is this a behavior specific to bound
    lists or am I doing something wrong.

    Thanks for the help! Code sniplets below.

    <CODE src="myproblempage.aspx.vb">
    Imports System
    Imports System.Data
    Imports System.Web
    Imports System.Web.UI
    Imports System.Web.UI.HtmlControls
    Imports System.Web.UI.WebControls
    Imports System.Web.SessionState

    Public Class sec_default
    Inherits System.Web.UI.Page

    Private strRoles() As String
    Private objSec As New Aurora.FKNCSecurity.clsSecurity()

    Protected WithEvents btnSearch As System.Web.UI.WebControls.Button
    Protected WithEvents divSearch As
    System.Web.UI.HtmlControls.HtmlGenericControl
    Protected WithEvents WebHeader1 As WebHeader
    Protected WithEvents cboGroups As System.Web.UI.WebControls.DropDownList
    Protected WithEvents cboOptions As
    System.Web.UI.WebControls.DropDownList
    Protected WithEvents grdMain As System.Web.UI.WebControls.DataGrid
    Protected WithEvents cboPickFunction As
    System.Web.UI.WebControls.DropDownList
    Protected WithEvents cboPickOption As
    System.Web.UI.WebControls.DropDownList
    Protected WithEvents cboPickGroup As
    System.Web.UI.WebControls.DropDownList

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub
    InitializeComponent()

    End Sub

    Private 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

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    Dim strUser As String = Request.ServerVariables("AUTH_USER")
    objSec.Username = strUser
    strRoles = objSec.GetRoles()

    ' Check to ensure user has SOME rights to this page.
    If IsNothing(strRoles) Then
    Response.Redirect("default.aspx")
    End If

    Dim objDS As System.Data.DataSet
    objDS = objSec.GetMenu()
    WebHeader1.LoadMenu(objDS)

    LoadLists()
    End Sub

    Private Function LoadLists()
    Dim mObj As New FKNCSecurity.clsADSecurity()
    Dim strGroups() As String = mObj.GetADGroupList()
    strGroups.Sort(strGroups)

    cboGroups.DataSource = strGroups
    cboGroups.DataBind()

    cboPickGroup.DataSource = strGroups
    cboPickGroup.DataBind()

    Dim objDB As New FKNCDataLayer.clsDBConn()
    Dim objDS As DataSet
    Dim strParams(0, 1) As String
    objDS = objDB.ExecuteSPReturnDS("usp_Get_Menu_Options_List",
    strParams, "FKNC_CCT")
    Dim i As Integer
    Dim strOptions(objDS.Tables(0).Rows.Count - 1, 1) As String
    For i = 0 To objDS.Tables(0).Rows.Count - 1
    strOptions(i, 0) = Trim(objDS.Tables(0).Rows(i)(0))
    strOptions(i, 1) = Trim(objDS.Tables(0).Rows(i)(1))
    Next
    cboOptions.DataSource = strOptions
    cboOptions.DataBind()

    cboPickOption.DataSource = strOptions
    cboPickOption.DataBind()
    'usp_Get_Menu_Options_List
    End Function


    Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles btnSearch.Click
    Search(cboGroups.SelectedItem.Value, cboOptions.SelectedItem.Value)
    End Sub

    Public Function Search(ByVal strGroupName As String, ByVal strOption As
    String) As Boolean
    Dim objDB As New FKNCDataLayer.clsDBConn()
    Dim strParams(1, 1) As String
    strParams(0, 0) = "@vchGroupName"
    'strParams(0, 1) = strGroupName
    strParams(0, 1) = "IT_Ops_Projects"
    strParams(1, 0) = "@vchOptionName"
    strParams(1, 1) = strOption
    Dim objDS As DataSet =
    objDB.ExecuteSPReturnDS("usp_Get_Menu_Security_Items", strParams,
    "FKNC_CCT")
    grdMain.DataSource = objDS
    grdMain.DataBind()
    End Function
    End Class
    </CODE>

    <CODE src="myproblempage.aspx">
    <%@ Register TagPrefix="FKNC" TagName="WebHeader" src="WebHeader.ascx" %>
    <%@ Page Language="vb" AutoEventWireup="false"
    Codebehind="myproblempage.aspx.vb" Inherits="Aurora.sec_default" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>ba_default</title>
    <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
    <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5"
    name="vs_targetSchema">
    <LINK href="styles.css" type="text/css" rel="stylesheet">
    </HEAD>
    <body onload="Form1.cboGroups.focus();" MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <table id="tblMain">
    <tr>
    <td vAlign="top" colSpan="2" height="105"><FKNC:WEBHEADER
    id="WebHeader1" runat="Server" width="100%"></FKNC:WEBHEADER></td>
    </tr>
    <tr>
    <td vAlign="top" width="200">
    <table height="100%" cellSpacing="0" cellPadding="0" width="100%"
    border="0" ID="Table1">
    <tr>
    <td vAlign="top" width="200">
    <DIV>
    <table height="100%" cellSpacing="0" cellPadding="4" width="200"
    border="0" ID="Table2">
    <tr>
    <td class="tdPageHead" align="middle">Security Module</td>
    </tr>
    <tr>
    <td class="tdSearch" vAlign="top">&nbsp;Search Menu
    <div id="divSearch" runat="server">
    <table cellSpacing="0" cellPadding="0" border="0" ID="Table3">
    <tr>
    <td class="tdSpacer"></td>
    </tr>
    <tr>
    <td class="tdSearchItem">Group Name</td>
    </tr>
    <tr>
    <td><asp:DropDownList EnableViewState="True" ID="cboGroups"
    runat="server" Width="190"></asp:DropDownList></td>
    </tr>
    <tr>
    <td class="tdSpacer"></td>
    </tr>
    <tr>
    <td class="tdSearchItem">System Area</td>
    </tr>
    <tr>
    <td><asp:DropDownList ID="cboOptions" runat="server"
    Width="190"></asp:DropDownList></td>
    </tr>
    </table>
    </div>
    &nbsp;
    <div align="center"><asp:button id="btnSearch" runat="server"
    text="Search"></asp:button></div>
    </td>
    </tr>
    </table>
    </DIV>
    </td>
    </tr>
    </table>
    </td>
    <td vAlign="top" align="middle">
    <TABLE style="WIDTH: 768px; HEIGHT: 568px" cellSpacing="0"
    cellPadding="0" border="0">
    <TBODY>
    <TR>
    <td vAlign="top" colspan="7">
    <table cellSpacing="0" cellPadding="0" width="100%" border="0">
    <tr>
    <td style="BORDER-BOTTOM: blue thin solid; HEIGHT: 157px">
    <div id="divGrid">
    <asp:DataGrid ID="grdMain" Runat="server" BackColor="#eeeeee"
    HorizontalAlign="Center" Font-Name="Verdana" CellPadding="4" Font-Size="9pt"
    AutoGenerateColumns="False" Width="100%">
    <HeaderStyle CssClass="tdPageHead" HorizontalAlign="Center"
    />
    <AlternatingItemStyle BackColor="White" />
    <Columns>
    <asp:BoundColumn DataField="id" HeaderText="ID"
    Visible="False"></asp:BoundColumn>
    <asp:BoundColumn DataField="groupname"
    HeaderText="Group"></asp:BoundColumn>
    <asp:BoundColumn DataField="description" HeaderText="System
    Area"></asp:BoundColumn>
    <asp:BoundColumn DataField="funct"
    HeaderText="Function"></asp:BoundColumn>
    <asp:ButtonColumn ItemStyle-HorizontalAlign="Center"
    ItemStyle-ForeColor="Black" Text="Delete" HeaderText=""></asp:ButtonColumn>
    </Columns>
    </asp:DataGrid>
    </div>
    </td>
    </tr>
    </table>
    <TABLE id="Table4" cellSpacing="0" cellPadding="0" width="100%"
    border="0">
    <TR>
    <TD class="tdArea" style="BORDER-BOTTOM: blue thin solid;
    HEIGHT: 25px">&nbsp;Group:</TD>
    <TD class="tdArea" style="BORDER-RIGHT: blue thin solid; WIDTH:
    170px; BORDER-BOTTOM: blue thin solid">
    <asp:DropDownList id="cboPickGroup" Runat="server"
    Width="190"></asp:DropDownList></TD>
    <TD class="tdArea" style="BORDER-BOTTOM: blue thin
    solid">&nbsp;System Area:</TD>
    <TD class="tdArea" style="BORDER-RIGHT: blue thin solid; WIDTH:
    170px; BORDER-BOTTOM: blue thin solid">
    <asp:DropDownList id="cboPickOption" Runat="server"
    Width="190"></asp:DropDownList></TD>
    <TD class="tdArea" style="BORDER-BOTTOM: blue thin
    solid">&nbsp;Function:</TD>
    <TD class="tdArea" style="WIDTH: 170px; BORDER-BOTTOM: blue thin
    solid">
    <asp:DropDownList id="cboPickFunction" Runat="server"
    Width="190">
    <asp:ListItem Value="VIEW">VIEW</asp:ListItem>
    <asp:ListItem Value="UPDATE">UPDATE</asp:ListItem>
    </asp:DropDownList>
    </TD>
    </TR>
    </TABLE>
    </td>
    </TR>
    </TBODY>
    </TABLE>
    </td>
    </tr>
    </table>
    </form>
    </body>
    </HTML>
    </CODE>
    Anthony Sullivan, Dec 22, 2003
    #1
    1. Advertising

  2. Sorry for spamming the group. I found the answer on my own after posting
    this. Should've looked harder before posting.

    FYI and I'm sure you all know this already. As simple If statement fixed my
    problem...

    If not Page.IsPostBack Then
    'Process Loading of DropDownLists
    End If

    Thanks anyway!

    Anthony Sullivan


    "Anthony Sullivan" <> wrote in message
    news:...
    > I have a DropDownList that I am binding to an array that has a list of
    > Active Directory Groups in it. I have a couple of problems that I am
    > experiencing and I'm wondering if someone could help.
    >
    > First, We have about 155 groups in our AD and pulling that entire list

    takes
    > about 10 seconds on our network. I expect this to improve slightly when we
    > move to a production environment but not enough for my liking. Currently

    the
    > code used to populate this DropDownList control is called from the
    > Page_Load. What is the best way to cache this information so that it isn't
    > loaded everytime the page loads.
    >
    > Second, once the DropDownList is populated everything works fine until the
    > user submits the form. For some reason the value is not being passed or
    > retained upon submission. When I try to reference the object serverside it
    > thinks that the object selected was the first item in the list regardless

    of
    > what was actually selected. I have another scenario where the options are
    > hardcoded and this doesn't not happen. Is this a behavior specific to

    bound
    > lists or am I doing something wrong.
    >
    > Thanks for the help! Code sniplets below.
    >
    > <CODE src="myproblempage.aspx.vb">
    > Imports System
    > Imports System.Data
    > Imports System.Web
    > Imports System.Web.UI
    > Imports System.Web.UI.HtmlControls
    > Imports System.Web.UI.WebControls
    > Imports System.Web.SessionState
    >
    > Public Class sec_default
    > Inherits System.Web.UI.Page
    >
    > Private strRoles() As String
    > Private objSec As New Aurora.FKNCSecurity.clsSecurity()
    >
    > Protected WithEvents btnSearch As System.Web.UI.WebControls.Button
    > Protected WithEvents divSearch As
    > System.Web.UI.HtmlControls.HtmlGenericControl
    > Protected WithEvents WebHeader1 As WebHeader
    > Protected WithEvents cboGroups As

    System.Web.UI.WebControls.DropDownList
    > Protected WithEvents cboOptions As
    > System.Web.UI.WebControls.DropDownList
    > Protected WithEvents grdMain As System.Web.UI.WebControls.DataGrid
    > Protected WithEvents cboPickFunction As
    > System.Web.UI.WebControls.DropDownList
    > Protected WithEvents cboPickOption As
    > System.Web.UI.WebControls.DropDownList
    > Protected WithEvents cboPickGroup As
    > System.Web.UI.WebControls.DropDownList
    >
    > #Region " Web Form Designer Generated Code "
    >
    > 'This call is required by the Web Form Designer.
    > <System.Diagnostics.DebuggerStepThrough()> Private Sub
    > InitializeComponent()
    >
    > End Sub
    >
    > Private 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
    >
    > #End Region
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > Dim strUser As String = Request.ServerVariables("AUTH_USER")
    > objSec.Username = strUser
    > strRoles = objSec.GetRoles()
    >
    > ' Check to ensure user has SOME rights to this page.
    > If IsNothing(strRoles) Then
    > Response.Redirect("default.aspx")
    > End If
    >
    > Dim objDS As System.Data.DataSet
    > objDS = objSec.GetMenu()
    > WebHeader1.LoadMenu(objDS)
    >
    > LoadLists()
    > End Sub
    >
    > Private Function LoadLists()
    > Dim mObj As New FKNCSecurity.clsADSecurity()
    > Dim strGroups() As String = mObj.GetADGroupList()
    > strGroups.Sort(strGroups)
    >
    > cboGroups.DataSource = strGroups
    > cboGroups.DataBind()
    >
    > cboPickGroup.DataSource = strGroups
    > cboPickGroup.DataBind()
    >
    > Dim objDB As New FKNCDataLayer.clsDBConn()
    > Dim objDS As DataSet
    > Dim strParams(0, 1) As String
    > objDS = objDB.ExecuteSPReturnDS("usp_Get_Menu_Options_List",
    > strParams, "FKNC_CCT")
    > Dim i As Integer
    > Dim strOptions(objDS.Tables(0).Rows.Count - 1, 1) As String
    > For i = 0 To objDS.Tables(0).Rows.Count - 1
    > strOptions(i, 0) = Trim(objDS.Tables(0).Rows(i)(0))
    > strOptions(i, 1) = Trim(objDS.Tables(0).Rows(i)(1))
    > Next
    > cboOptions.DataSource = strOptions
    > cboOptions.DataBind()
    >
    > cboPickOption.DataSource = strOptions
    > cboPickOption.DataBind()
    > 'usp_Get_Menu_Options_List
    > End Function
    >
    >
    > Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles btnSearch.Click
    > Search(cboGroups.SelectedItem.Value,

    cboOptions.SelectedItem.Value)
    > End Sub
    >
    > Public Function Search(ByVal strGroupName As String, ByVal strOption

    As
    > String) As Boolean
    > Dim objDB As New FKNCDataLayer.clsDBConn()
    > Dim strParams(1, 1) As String
    > strParams(0, 0) = "@vchGroupName"
    > 'strParams(0, 1) = strGroupName
    > strParams(0, 1) = "IT_Ops_Projects"
    > strParams(1, 0) = "@vchOptionName"
    > strParams(1, 1) = strOption
    > Dim objDS As DataSet =
    > objDB.ExecuteSPReturnDS("usp_Get_Menu_Security_Items", strParams,
    > "FKNC_CCT")
    > grdMain.DataSource = objDS
    > grdMain.DataBind()
    > End Function
    > End Class
    > </CODE>
    >
    > <CODE src="myproblempage.aspx">
    > <%@ Register TagPrefix="FKNC" TagName="WebHeader" src="WebHeader.ascx" %>
    > <%@ Page Language="vb" AutoEventWireup="false"
    > Codebehind="myproblempage.aspx.vb" Inherits="Aurora.sec_default" %>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    > <HTML>
    > <HEAD>
    > <title>ba_default</title>
    > <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
    > <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
    > <meta content="JavaScript" name="vs_defaultClientScript">
    > <meta content="http://schemas.microsoft.com/intellisense/ie5"
    > name="vs_targetSchema">
    > <LINK href="styles.css" type="text/css" rel="stylesheet">
    > </HEAD>
    > <body onload="Form1.cboGroups.focus();" MS_POSITIONING="GridLayout">
    > <form id="Form1" method="post" runat="server">
    > <table id="tblMain">
    > <tr>
    > <td vAlign="top" colSpan="2" height="105"><FKNC:WEBHEADER
    > id="WebHeader1" runat="Server" width="100%"></FKNC:WEBHEADER></td>
    > </tr>
    > <tr>
    > <td vAlign="top" width="200">
    > <table height="100%" cellSpacing="0" cellPadding="0" width="100%"
    > border="0" ID="Table1">
    > <tr>
    > <td vAlign="top" width="200">
    > <DIV>
    > <table height="100%" cellSpacing="0" cellPadding="4" width="200"
    > border="0" ID="Table2">
    > <tr>
    > <td class="tdPageHead" align="middle">Security Module</td>
    > </tr>
    > <tr>
    > <td class="tdSearch" vAlign="top">&nbsp;Search Menu
    > <div id="divSearch" runat="server">
    > <table cellSpacing="0" cellPadding="0" border="0"

    ID="Table3">
    > <tr>
    > <td class="tdSpacer"></td>
    > </tr>
    > <tr>
    > <td class="tdSearchItem">Group Name</td>
    > </tr>
    > <tr>
    > <td><asp:DropDownList EnableViewState="True"

    ID="cboGroups"
    > runat="server" Width="190"></asp:DropDownList></td>
    > </tr>
    > <tr>
    > <td class="tdSpacer"></td>
    > </tr>
    > <tr>
    > <td class="tdSearchItem">System Area</td>
    > </tr>
    > <tr>
    > <td><asp:DropDownList ID="cboOptions" runat="server"
    > Width="190"></asp:DropDownList></td>
    > </tr>
    > </table>
    > </div>
    > &nbsp;
    > <div align="center"><asp:button id="btnSearch" runat="server"
    > text="Search"></asp:button></div>
    > </td>
    > </tr>
    > </table>
    > </DIV>
    > </td>
    > </tr>
    > </table>
    > </td>
    > <td vAlign="top" align="middle">
    > <TABLE style="WIDTH: 768px; HEIGHT: 568px" cellSpacing="0"
    > cellPadding="0" border="0">
    > <TBODY>
    > <TR>
    > <td vAlign="top" colspan="7">
    > <table cellSpacing="0" cellPadding="0" width="100%" border="0">
    > <tr>
    > <td style="BORDER-BOTTOM: blue thin solid; HEIGHT: 157px">
    > <div id="divGrid">
    > <asp:DataGrid ID="grdMain" Runat="server"

    BackColor="#eeeeee"
    > HorizontalAlign="Center" Font-Name="Verdana" CellPadding="4"

    Font-Size="9pt"
    > AutoGenerateColumns="False" Width="100%">
    > <HeaderStyle CssClass="tdPageHead" HorizontalAlign="Center"
    > />
    > <AlternatingItemStyle BackColor="White" />
    > <Columns>
    > <asp:BoundColumn DataField="id" HeaderText="ID"
    > Visible="False"></asp:BoundColumn>
    > <asp:BoundColumn DataField="groupname"
    > HeaderText="Group"></asp:BoundColumn>
    > <asp:BoundColumn DataField="description"

    HeaderText="System
    > Area"></asp:BoundColumn>
    > <asp:BoundColumn DataField="funct"
    > HeaderText="Function"></asp:BoundColumn>
    > <asp:ButtonColumn ItemStyle-HorizontalAlign="Center"
    > ItemStyle-ForeColor="Black" Text="Delete"

    HeaderText=""></asp:ButtonColumn>
    > </Columns>
    > </asp:DataGrid>
    > </div>
    > </td>
    > </tr>
    > </table>
    > <TABLE id="Table4" cellSpacing="0" cellPadding="0" width="100%"
    > border="0">
    > <TR>
    > <TD class="tdArea" style="BORDER-BOTTOM: blue thin solid;
    > HEIGHT: 25px">&nbsp;Group:</TD>
    > <TD class="tdArea" style="BORDER-RIGHT: blue thin solid;

    WIDTH:
    > 170px; BORDER-BOTTOM: blue thin solid">
    > <asp:DropDownList id="cboPickGroup" Runat="server"
    > Width="190"></asp:DropDownList></TD>
    > <TD class="tdArea" style="BORDER-BOTTOM: blue thin
    > solid">&nbsp;System Area:</TD>
    > <TD class="tdArea" style="BORDER-RIGHT: blue thin solid;

    WIDTH:
    > 170px; BORDER-BOTTOM: blue thin solid">
    > <asp:DropDownList id="cboPickOption" Runat="server"
    > Width="190"></asp:DropDownList></TD>
    > <TD class="tdArea" style="BORDER-BOTTOM: blue thin
    > solid">&nbsp;Function:</TD>
    > <TD class="tdArea" style="WIDTH: 170px; BORDER-BOTTOM: blue

    thin
    > solid">
    > <asp:DropDownList id="cboPickFunction" Runat="server"
    > Width="190">
    > <asp:ListItem Value="VIEW">VIEW</asp:ListItem>
    > <asp:ListItem Value="UPDATE">UPDATE</asp:ListItem>
    > </asp:DropDownList>
    > </TD>
    > </TR>
    > </TABLE>
    > </td>
    > </TR>
    > </TBODY>
    > </TABLE>
    > </td>
    > </tr>
    > </table>
    > </form>
    > </body>
    > </HTML>
    > </CODE>
    >
    >
    Anthony Sullivan, Dec 22, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sunil panda

    Lower bound & Upper bound

    sunil panda, Dec 25, 2003, in forum: Java
    Replies:
    9
    Views:
    7,217
    thushara wijeratna
    Oct 7, 2008
  2. Rhiner Dan
    Replies:
    1
    Views:
    738
    Mike Wahler
    Mar 27, 2005
  3. Mario Krsnic
    Replies:
    0
    Views:
    368
    Mario Krsnic
    Jun 23, 2006
  4. Phillip Vong
    Replies:
    0
    Views:
    410
    Phillip Vong
    Jul 27, 2006
  5. Max2006
    Replies:
    2
    Views:
    415
    Max2006
    Jul 26, 2007
Loading...

Share This Page