Solved

Populate Dropdownlist

Posted on 2013-10-22
3
333 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
  • 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 500 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

803 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