Solved

NEED ASSISTANCE WITH DDL & TEXTBOX ASSOCIATE & INSERTION

Posted on 2014-10-14
4
153 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 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