Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Populate Dropdownlist

Posted on 2013-10-22
3
Medium Priority
?
345 Views
Last Modified: 2013-10-22
I need to populate a dropdownlist dynamically. After selecting a row from a gridview the panel populated. But need help with dropdownlists.

    <div id="idGridViewClass" class="AddClass">
        <asp:panel id="DisplayAddPanelAll" runat="server" visible="false" >
            <asp:Label ID="lblEmployeeID" runat="server" Visible="true" CssClass="CsslblEmployeeID"/>
            <asp:Label cssclass="CurvedTitleAdd" ID="lblTitleAdd" runat="server"/>

            <asp:Label runat="server" ID="lblEmployeeNumber" CssClass="CsslblEmployeeNumber" Text="Employee #:"/>     
            <asp:TextBox runat="server" ID="txtEmployeeNumber" MaxLength="50" Width="175px" CssClass="CsstxtEmployeeNumber"/>

            <asp:Label runat="server" ID="lblFirstName" CssClass="CsslblFirstName" Text="First Name:"/>     
            <asp:TextBox runat="server" ID="txtFirstName" AutoPostBack="true" MaxLength="50" Width="175px" CssClass="CsstxtFirstName" />

            <asp:Label runat="server" ID="lblKnownName" CssClass="CsslblKnownName" Text="Known Name:"/>     
            <asp:TextBox runat="server" ID="txtKnownName" MaxLength="50" Width="175px" CssClass="CsstxtKnownName"/>

            <asp:Label runat="server" ID="lblMiddleName" CssClass="CsslblMiddleName" Text="Middle Name:"/>     
            <asp:TextBox runat="server" ID="txtMiddleName" MaxLength="50" Width="175px" CssClass="CsstxtMiddleName"/>

            <asp:Label runat="server" ID="lblLastName" CssClass="CsslblLastName" Text="Last Name:"/>     
            <asp:TextBox runat="server" ID="txtLastName" MaxLength="50" Width="175px" CssClass="CsstxtLastName"/>

            <asp:Label runat="server" ID="lblEmployeeID" CssClass="CsslblEmployeeID" Text="Department:"/>     
            <asp:dropdownlist runat="server" ID="ddlEmployeeID" CssClass="CssddlEmployeeID" AutoPostBack="True">
                <asp:ListItem Text="<Select>" Value="0" />
            </asp:dropdownlist>
			
            <asp:Label runat="server" ID="lblGenderID" CssClass="CsslblGenderID" Text="Gender:"/>     
            <asp:dropdownlist runat="server" ID="ddlGenderID" CssClass="CssddlGenderID">
                <asp:ListItem Text="<Select>" Value="0" />
            </asp:dropdownlist>

			<asp:ImageButton ID="btnHideEmployeeAdminPanelButton" runat="server" CssClass="CssHideEmployeeAdminPanelButton" ImageUrl="~/images/close.png"  Width="20" Height="20" OnClick="btnHideEmployeeAdminPanelButton_Click"/>
            <asp:ImageButton ID="btnSaveEmployeeAdminPanelButton" runat="server" CssClass="CssSaveEmployeeAdminPanelButton" ImageUrl="~/images/save-icon.png"  Width="40" Height="40" OnClick="btnSaveEmployeeAdminPanelButton_Click"/>
        </asp:panel>
    </div>
///////////////////////////////////////////////////////////////////////////////////////////////////////////	
///////////////////////////////////////////////////////////////////////////////////////////////////////////	
///////////////////////////////////////////////////////////////////////////////////////////////////////////	
	    private void PopulateDetailsPanel(int EmployeeID, bool blInActive)
        {
            //RETURN MESSAGE
            string strReturnMessage = null;

            try 
            {
                //GET Employee DETAILS
                Admin.EmployeeDetails EmployeeDetails = new Admin.EmployeeDetails();
                WorkStations.EmployeewrkStation MyWrkStation = new Factories.EmployeeWrkStation();
                EmployeeDetails = MyWrkStation.GetEmployeeDetails(out strReturnMessage, EmployeeID, blInActive);
				
                //Employee NUMBER TEXTBOX
                txtEmployeeNumber.Text = EmployeeDetails.EmployeeNumber;

                //FIRST NAME TEXTBOX
                txtFirstName.Text = EmployeeDetails.FirstName;

                //KNOWN NAME TEXTBOX
                txtKnownName.Text = EmployeeDetails.KnownName;

                //MIDDLE NAME TEXTBOX
                txtMiddleName.Text = EmployeeDetails.MiddleName;

                //LAST NAME TEXTBOX
                txtLastName.Text = EmployeeDetails.LastName;

                //DEPARTMENT ID DROPDOWLIST
                ddlDepartmentID.Text = EmployeeDetails.DepartmentID.ToString();
				
                //GENDER ID DROPDOWNLIST
                ddlGenderID.Text = EmployeeDetails.GenderID.ToString();
            }
            catch (Exception ex)
            {
                strReturnMessage = ex.Message.ToString();
            }
        }
				

Open in new window

0
Comment
Question by:RedXavier2k4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 39591987
Your question is not really clear. Could you explain a bit more on what you are trying to achieve?
And are you getting any errors?
0
 

Author Comment

by:RedXavier2k4
ID: 39592018
in my code behind PopulateDetailsPanel function I am populating the textboxes and the dropdownlists with the GetEmployeeDetails function. The data is coming through and the textboxes are being populated. How do I populate the dropdownlists with this data:


ddlGenderID.SelectedValue = EmployeeDetails.GenderID.ToString();

would selectedvalue populate the dropdownlist with the value of EmployeeDetails.GenderID.ToString();
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 2000 total points
ID: 39592056
I see your ddl isn't having any DataSource. So first you will have to populate it with the Gender values may be hard-coded or from database. Then only you can set the value like:
ddlGenderID.SelectedValue = EmployeeDetails.GenderID.ToString();
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question