Solved

Populate Dropdownlist

Posted on 2013-10-22
3
336 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

808 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