Solved

TEXTBOX DEPENDENCY ON DROPDOWN SELECTION

Posted on 2014-10-07
2
121 Views
Last Modified: 2014-10-08
Please review the attach code behind segment.    Section one of the code below works fine populating TextBox    "EmpAP" data from the DB when a corresponding value is selected from "CondBY".    However, I have a second drop down "InspBy1" in which I need to accomplish the same thing.

I need assistance with the arrangement of the code.  

-------------------------------------------------------------------------------------------------------------------------------------------------------


protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            FillDropdown();
        }
    }
    //Filldrop down
    void FillDropdown()
    {

        SqlConnection con = new SqlConnection("");//connection string;
        con.Open();

        SqlCommand cmd = new SqlCommand("select * from EmpData", con);
        SqlDataAdapter dap = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        dap.Fill(ds);
        CondBY.DataSource = ds;
        CondBY.DataTextField = "Name1";//Database table filed name for display in dropdown
        CondBY.DataValueField = "EmpNo";//display in textbox when select dropdown field
        CondBY.DataBind();
    }


    protected void CondBY_SelectedIndexChanged(object sender, EventArgs e)
    {
        EmpAP.Text = CondBY.SelectedValue.ToString();// get value form dropdown

    }


----------------------------------------------------------------------------------------------------------------------------------------------------------

    private void Page_Load(object sender, EventArgs e)
    {


        SqlConnection con = new SqlConnection("");//connection string;
        con.Open();

        SqlCommand cmd = new SqlCommand("select * from EmpData", con);
        SqlDataAdapter dap = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        dap.Fill(ds);
        InspBy1.DataSource = ds;
        InspBy1.DataTextField = "Name1";//Database table filed name for display in dropdown
        InspBy1.DataValueField = "EmpNo";//display in textbox when select dropdown field
        InspBy1.DataBind();
    }


    protected void InspBy1_SelectedIndexChanged(object sender, EventArgs e)
    {
        EmpAP1.Text = InspBy1.SelectedValue.ToString();// get value form dropdown


    }


}
0
Comment
Question by:BOEING39
2 Comments
 
LVL 2

Accepted Solution

by:
Vishal Patil earned 500 total points
ID: 40367696
Hello Boeing39,

If i have understood your question correctly,
Arrange code in following manner :
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            FillDropdown(CondBY);
            FillDropdown(InspBy1);
        }
    }
    //Filldrop down
    void FillDropdown(DropDownList ddl)
    {

        SqlConnection con = new SqlConnection("");//connection string;
        con.Open();

        SqlCommand cmd = new SqlCommand("select * from EmpData", con);
        SqlDataAdapter dap = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        dap.Fill(ds);
        ddl.DataSource = ds;
        ddl.DataTextField = "Name1";//Database table filed name for display in dropdown
        ddl.DataValueField = "EmpNo";//display in textbox when select dropdown field
        ddl.DataBind();
    }


    protected void CondBY_SelectedIndexChanged(object sender, EventArgs e)
    {
        EmpAP.Text = CondBY.SelectedValue.ToString();// get value form dropdown

    }
    protected void InspBy1_SelectedIndexChanged(object sender, EventArgs e)
    {
        EmpAP1.Text = InspBy1.SelectedValue.ToString();// get value form dropdown
    }

Open in new window

0
 

Author Closing Comment

by:BOEING39
ID: 40368350
Thx for the quick response - that took care of the problem.


Thx Again
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

15 Experts available now in Live!

Get 1:1 Help Now