ViewState in my Wizard

末鹿安然 提交于 2019-12-12 01:03:17

问题


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..


回答1:


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);


来源:https://stackoverflow.com/questions/11693777/viewstate-in-my-wizard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!