Solved

Populate Dropdownlist

Posted on 2013-10-22
3
326 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now