0

I have a Wizard to Add an Employee from my org. In Step1, I have few controls, one of them is EmpID (PK). The problem arrives in Step2, where I have only one control that is DropDownList1 which is binded from Datasource (code-behind). I want this value of DropDownList1 and EmpID from previous Step to insert it into another table called 'dbo.Emp_Skills'.

'dbo.Emp_skills' table has 2 columns:

EmpID (FK) | SkillID (FK)

How do I insert value of EmpID into this table when it is not actually saved? I can simply insert value of my DropDownList like this after my connections..

cmd.Parameters.AddWithValue("@SkillID", DropDownList1.SelectedValue);

But how do I insert the EmpID into the table? EmpID and CertID are both FK in the dbo.Emp_Cert.. Will it be a problem??

I have used ViewState in Page_Load like this-

Well I have used simple ViewState something like this-

 if(ViewState["NameOfUser"] != null)
            NameLabel.Text = ViewState["NameOfUser"].ToString();
        else
            NameLabel.Text = "Not set yet...";

I used Label1 Control in Step2 of Wizard.

protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
        {
            ViewState["NameOfUser"] =  TextBox1.Text;
            NameLabel.Text = TextBox1.Text;

        }

And then I used to insert that-

cmd.Parameters.AddWithValue("@EmpID", TextBox1.Text);
cmd.Parameters.AddWithValue("@SkillID", DropDownList1.SelectedValue);

But it is not working..

11
  • where is EmpID value in step1 ? IN which control it is present ? Jul 27, 2012 at 19:07
  • Hello.. It is present in TextBox1..
    – Girish
    Jul 28, 2012 at 6:53
  • use this cmd.Parameters.AddWithValue("@SkillID", DropDownList1.SelectedValue); cmd.Parameters.AddWithValue("@EmpID", ViewState["NameOfUser"].ToString()); Jul 28, 2012 at 9:13
  • Thanks.. But when I click 'Next' in Step1, the NameLabel is not getting updated. It still says 'Not set yet...'.
    – Girish
    Jul 28, 2012 at 9:43
  • in which page event you had placed this code ` if(ViewState["NameOfUser"] != null) NameLabel.Text = ViewState["NameOfUser"].ToString(); else NameLabel.Text = "Not set yet...";` ?????? Jul 28, 2012 at 11:20

1 Answer 1

0

Assuming you are using asp.net wizard control, your TextBox1 is still there on the page, and you can access its value.

This would work.

cmd.Parameters.AddWithValue("@SkillID", DropDownList1.SelectedValue);
cmd.Parameters.AddWithValue("@EmpID", TextBox1.Text);
3
  • Yes, I use asp.net wizard control and I tried that ways, but it was not working..
    – Girish
    Jul 28, 2012 at 7:58
  • It is not giving any errors. Just that it doesn't store values into the table .
    – Girish
    Jul 28, 2012 at 8:02
  • Debug and check the value for TextBox1.Text. If you have ViewState enabled, its value should persist event after you move ahead in the wizard Jul 28, 2012 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.