?
Solved

Populate Dropdownlist

Posted on 2013-10-22
3
Medium Priority
?
342 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

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
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…
Suggested Courses

801 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