?
Solved

NEED ASSISTANCE WITH DDL & TEXTBOX ASSOCIATE & INSERTION

Posted on 2014-10-14
4
Medium Priority
?
159 Views
Last Modified: 2014-10-14
Please review the attached code.    I have a DDL "CondBY" that when a selection is made it auto populates a TEXTBOX "EmpAP" with associated employee numbers from "EmpData".   When viewing the form on the local host when the name is selected both the name and employee numbers are rendered correctly; however, when submitted both table columns:   CondBY and EmpAP are filled with the employee number.   I need assistance with the code to get the "CondBY" selected name in as well.


cmd.Parameters.Add("@Dates", System.Data.SqlDbType.DateTime, 8).Value = DateTime.Now;
        cmd.Parameters.Add("@Station1", System.Data.SqlDbType.NVarChar, 50).Value = Station1.SelectedValue;
        cmd.Parameters.Add("@Ship1", System.Data.SqlDbType.NVarChar, 50).Value = Ship1.SelectedValue;
        cmd.Parameters.Add("@CondBy", System.Data.SqlDbType.NVarChar, 50).Value = CondBY.SelectedValue;
        cmd.Parameters.Add("@EmpAP", System.Data.SqlDbType.NVarChar, 50).Value = EmpAP.Text;
        cmd.Parameters.Add("@EmpAP1", System.Data.SqlDbType.NVarChar, 50).Value = EmpAP1.Text;
        cmd.Parameters.Add("@Doc1", System.Data.SqlDbType.NVarChar, 50).Value = Doc1.Text;
        cmd.Parameters.Add("@Doc2", System.Data.SqlDbType.NVarChar, 50).Value = Doc2.Text;
        cmd.Parameters.Add("@Discussion", System.Data.SqlDbType.NVarChar, 4000).Value = Discussion.Text;
        cmd.Parameters.Add("@InspBy1", System.Data.SqlDbType.NVarChar, 50).Value = InspBy1.SelectedValue;
        cmd.Parameters.Add("@Conmx", System.Data.SqlDbType.NVarChar, 50).Value = Conmx.Text;
        cmd.Parameters.Add("@APno", System.Data.SqlDbType.NVarChar, 50).Value = APno.Text;

        cmd.ExecuteNonQuery();
        con.Close();

Open in new window


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


    }

}

Open in new window

0
Comment
Question by:BOEING39
[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
  • 2
4 Comments
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 40380622
Shouldn't this line
cmd.Parameters.Add("@CondBy", System.Data.SqlDbType.NVarChar, 50).Value = CondBY.SelectedValue;

Open in new window

be
cmd.Parameters.Add("@CondBy", System.Data.SqlDbType.NVarChar, 50).Value = CondBY.SelectedItem.Text;

Open in new window

if you want the displayed text in your dropdown list?
0
 

Author Comment

by:BOEING39
ID: 40380792
The text is displaying both in the DDL /TextBox properly; however, it is just not being entered into the table correctly.    It is entering the employee number into both the name and employee number positions.   As I explained in the initial problem I have a DDL "CondBY" and a TextBox "EmpAP".   When the DDL name is selected the corresponding employee number fills the TextBox "EmpAP".   This all is rendering properly. However; when a submit occurs the employee number populates both the data columns "CondBY" and "EmpAP" data columns.   The employee name selected isn't going into the table.
0
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 2000 total points
ID: 40380826
Sorry, I typed that last part and didn't catch my error. If you want the employee name saved to the database you need to use the SelectedItem's text property, as shown in the provided code. The code you provided is using the selected value when saving to the database, and when setting the EmpAP textbox in the DDL's SelectedIndexChanged event.
0
 

Author Closing Comment

by:BOEING39
ID: 40380926
Thx that took care of it.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 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