Solved

NEED ASSISTANCE WITH DDL & TEXTBOX ASSOCIATE & INSERTION

Posted on 2014-10-14
4
148 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
  • 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 500 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

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

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

12 Experts available now in Live!

Get 1:1 Help Now