How to put Delete option in this User Management Wizard?
<p>I have developed User Management Module in the web-based application that I am working on it. By using ASP.NET Wizard control, it is developed to be worked as following:
First Step: it contains a TextBox for entering the username of employee
Second Step: it shows the information of the employee
Third Step: giving the user the role to access the system</p>

<p>If the user is not in the database, it will be added to the system after specifying a role for him and click on the Finish button. What I want now is the following: In the second step, when the user information be displayed, I want to put two options: Delete or Add/Edit Role
Delete will be enabled, if he is existed in the system
Add will be enabled all the time, for editing the role for the user</p>

<p>So is there any way to do that?</p>

<p>My code in ASP.NET and C# is as following:</p>

<p>ASP.NET:</p>

<pre><code>&lt;div id="wizard" align="center" runat="server"&gt;
        &lt;asp:Wizard ID="Wizard1" runat="server" DisplaySideBar="False" Width="63%" ActiveStepIndex="2"
            OnNextButtonClick="Wizard1_NextButtonClick" OnFinishButtonClick="Wizard1_FinishButtonClick"&gt;
            &lt;WizardSteps&gt;
                &lt;asp:WizardStep ID="WizardStep1" runat="server" Title="Employee Username/Network ID"&gt;
                    &lt;table border="0"&gt;
                        &lt;tr&gt;
                            &lt;td class="InputLabel"&gt;
                                Username:
                            &lt;/td&gt;
                            &lt;td class="InputControl"&gt;
                                &lt;asp:TextBox ID="TextBox1" runat="server" /&gt;
                            &lt;/td&gt;
                            &lt;td&gt;
                            &lt;span id="errorSpan" runat="server" style="color:Red;"&gt;&lt;/span&gt;
                            &lt;/td&gt;
                        &lt;/tr&gt;
                    &lt;/table&gt;
                &lt;/asp:WizardStep&gt;
                &lt;asp:WizardStep ID="WizardStep2" runat="server" Title="Manage User"&gt;
                    &lt;div class="content"&gt;
                        &lt;table&gt;
                            &lt;tr&gt;
                                &lt;td&gt;
                                    Name: 
                                    &lt;asp:Label ID="lblName" runat="server"&gt;&lt;/asp:Label&gt;
                                &lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td&gt;
                                    Username: 
                                    &lt;asp:Label ID="lblUsername" runat="server"&gt;&lt;/asp:Label&gt;
                                &lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td&gt;
                                    Division:
                                    &lt;asp:Label ID="lblDivision" runat="server"&gt;&lt;/asp:Label&gt;
                                &lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td&gt;
                                    Badge Number:
                                    &lt;asp:Label ID="lblBadgeNo" runat="server"&gt;&lt;/asp:Label&gt;
                                &lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td&gt;
                                    Job Title:
                                    &lt;asp:Label ID="lblJobTitle" runat="server"&gt;&lt;/asp:Label&gt;
                                &lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                    &lt;/div&gt;
                &lt;/asp:WizardStep&gt;
                &lt;asp:WizardStep ID="WizardStep3" runat="server" Title="Edit User Role"&gt;
                    &lt;div class="content"&gt;
                        &lt;table&gt;
                            &lt;caption&gt;
                                Current Role:
                                &lt;asp:Label ID="lblRole" runat="server"&gt;&lt;/asp:Label&gt;
                            &lt;/caption&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;asp:Label ID="Label1" runat="server" BackColor="#FFFF99" Font-Bold="True" ForeColor="#000099" /&gt;
                                &lt;asp:RadioButtonList ID="radio1" runat="server" TextAlign="left" RepeatDirection="Horizontal" 
                                    DataSourceID="SqlDataSource1" DataTextField="RoleName" DataValueField="RoleID"&gt;
                                    &lt;asp:ListItem id="option1" runat="server" Value="Admin" /&gt;
                                    &lt;asp:ListItem id="option2" runat="server" Value="Contribute" /&gt;
                                    &lt;asp:ListItem id="option3" runat="server" Value="Management" /&gt;
                                    &lt;asp:ListItem id="option4" runat="server" Value="User" /&gt;
                                &lt;/asp:RadioButtonList&gt;
                                &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                    ConnectionString="&lt;%$ ConnectionStrings:testConnectionString %&gt;" 
                                    SelectCommand="SELECT * FROM [Roles]"&gt;&lt;/asp:SqlDataSource&gt;
                                &lt;%--&lt;asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Clicked" /&gt;
                                &lt;span id="infoSpan" runat="server" style="color:Red;"&gt;&lt;/span&gt;--%&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                    &lt;/div&gt;
                &lt;/asp:WizardStep&gt;
            &lt;/WizardSteps&gt;
            &lt;HeaderTemplate&gt;
                &lt;ul id="wizHeader"&gt;
                    &lt;asp:Repeater ID="SideBarList" runat="server"&gt;
                        &lt;ItemTemplate&gt;
                            &lt;li&gt;&lt;a class="&lt;%# GetClassForWizardStep(Container.DataItem) %&gt;" title="&lt;%#Eval("Name")%&gt;"&gt;
                               &lt;%# Eval("Name")%&gt;&lt;/a&gt; &lt;/li&gt;
                        &lt;/ItemTemplate&gt;
                    &lt;/asp:Repeater&gt;
                &lt;/ul&gt;
            &lt;/HeaderTemplate&gt;
        &lt;/asp:Wizard&gt;
</code></pre>

<p>C#:</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
    {
        //Set the Wizard Step 0 as the initial wizard step when the page loads
        if (!Page.IsPostBack)
        {
            Wizard1.ActiveStepIndex = 0;
        }

        //For sending object to the Wizard1.PreRender
        Wizard1.PreRender += new EventHandler(Wizard1_PreRender);
    }


    protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {
        //If one of the items is selected AND a username exists in the Username session object update the user role
        string username = TextBox1.Text;

        if (!String.IsNullOrEmpty(radio1.SelectedValue) &amp;&amp; !String.IsNullOrEmpty(username))
        {
            string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdbTest;Integrated Security=True";

            //This for adding the new PMOD user to the system 
            string insertUserCommand = "INSERT INTO employee (Name, Username, JobTitle, BadgeNo, EmpOrgType, DivisionCode) values (@Name, @Username, @JobTitle, @BadgeNo, @EmpOrgType, @DivisionCode)";
            string cmdText = "SELECT Count(*) FROM employee WHERE Username = '" + username + "'";
            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                // Open DB connection.
                using (SqlCommand cmd = new SqlCommand(cmdText, conn))
                {
                    if ((int)cmd.ExecuteScalar() == 0){
                        //An object from ObjectUser class to get the user information from the Secure system and insert them to the database
                        ObjectUser user = new ObjectUser(username,true);

                        SqlCommand cmd2 = new SqlCommand(insertUserCommand, conn);
                        cmd2.Parameters.AddWithValue("@Name", user.Name);
                        cmd2.Parameters.AddWithValue("@Username", username);
                        cmd2.Parameters.AddWithValue("@JobTitle", user.GetProperty("EMP_TITLE"));
                        cmd2.Parameters.AddWithValue("@BadgeNo", user.GetProperty("EMP_BADGE_NUMBER"));
                        cmd2.Parameters.AddWithValue("@EmpOrgType", user.GetProperty("EMP_EMPTYPE"));
                        cmd2.Parameters.AddWithValue("@DivisionCode", user.Org.Division.SapCode);
                        cmd2.ExecuteNonQuery();
                    }

                }
            }

            //For updating the role of the user by deleting its current role and inserting a new role
            string deleteCommand = "DELETE FROM UserRole where Username=@Username";
            string insertCommand = "INSERT INTO UserRole (RoleID,Username) values(@RoleID,@Username)";
            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                //using (SqlCommand cmd = new SqlCommand(cmdText, conn))
                using (SqlCommand cmd = new SqlCommand(deleteCommand, conn))
                {
                    cmd.Parameters.AddWithValue("@Username", username);
                    cmd.ExecuteNonQuery();
                    //Now the insert
                    cmd.CommandText = insertCommand;
                    cmd.Parameters.Clear(); //need this because still has params from del comm
                    cmd.Parameters.AddWithValue("@RoleID", radio1.SelectedValue);
                    cmd.Parameters.AddWithValue("@Username", username);
                    cmd.ExecuteNonQuery();
                    //infoSpan.InnerText = String.Format("The users role has been updated to - {0}", radio1.SelectedValue);
                    //cmd.ExecuteScalar();
                    //infoSpan.InnerText = String.Format("The users role has been updated to - {0}", radio1.SelectedValue);
                }
            }

            Wizard1.Visible = false;
            wizard.InnerHtml = @"&lt;p&gt;&lt;b&gt;The task has been done successfully.&lt;/b&gt; &lt;br /&gt; &lt;a href='UserManagement.aspx'&gt;Edit Another User&lt;/a&gt;&lt;/p&gt;";
        }


    }


    //Method for checking the existence of the username in the database (retrun true or false)
    private bool CheckUsername(string username)
    {
        if (Service.GetPerson(username).GetProperty("RES_NETID").Equals("-"))
            return false;
        else if (Security.isPMODMember(username))
            return true;
        else
            return false;

        //string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdb;Integrated Security=True";
        //string cmdText = "SELECT Count(*) FROM employee WHERE Username = '" + username + "'";
        //using (SqlConnection conn = new SqlConnection(connString))
        //{
        //    conn.Open();
        //    // Open DB connection.
        //    using (SqlCommand cmd = new SqlCommand(cmdText, conn))
        //    {
        //        int count = (int)cmd.ExecuteScalar();
        //        // True (&gt; 0) when the username exists, false (= 0) when the username does not exist.
        //        return (count &gt; 0);
        //    }
        //}
    }


    protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        string username = TextBox1.Text;
        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdbTest;Integrated Security=True";

        switch (Wizard1.WizardSteps[e.NextStepIndex].ID)
        {
            case "WizardStep2":

                //For checking the user        
                if (!String.IsNullOrEmpty(username) &amp;&amp; CheckUsername(username))
                {
                    try
                    {
                        SqlConnection conn = new SqlConnection(connString);
                        conn.Open();
                        string cmdText = @"SELECT dbo.employee.Username, dbo.employee.Name, dbo.employee.JobTitle, dbo.employee.BadgeNo,
                                                ISNULL(dbo.Roles.RoleID, 3) AS RoleID, dbo.Divisions.DivisionName, dbo.Roles.RoleName
                                         FROM  dbo.Divisions INNER JOIN dbo.employee ON dbo.Divisions.SapCode = dbo.employee.DivisionCode
                                                LEFT OUTER JOIN dbo.Roles RIGHT OUTER JOIN dbo.UserRole ON dbo.Roles.RoleID = dbo.UserRole.RoleID ON
                                                dbo.employee.Username = dbo.UserRole.Username
                                         WHERE     (dbo.employee.Username = @Username)";
                        SqlCommand myCommand = new SqlCommand(cmdText, conn);
                        myCommand.Parameters.AddWithValue("@Username", username);
                        DataTable table = new DataTable();
                        SqlDataAdapter adapter = new SqlDataAdapter(myCommand);
                        adapter.Fill(table);

                        ObjectUser user = new ObjectUser(username, true);

                        string Name = user.Name;
                        string Username = user.ID;
                        string DivisionName = user.Org.Title;
                        string JobTitle = user.GetProperty("EMP_TITLE");
                        string BadgeNo = user.GetProperty("EMP_BADGE_NUMBER");
                        string role = "User";
                        string roleid = "4";
                        if (table.Rows.Count &gt; 0)
                        {
                            role = table.Rows[0]["RoleName"] as string;
                            roleid = table.Rows[0]["RoleID"].ToString();
                        }

                        lblName.Text = Name;
                        lblUsername.Text = Username;
                        lblDivision.Text = DivisionName;
                        lblJobTitle.Text = JobTitle;
                        lblBadgeNo.Text = BadgeNo;

                        lblRole.Text = role;
                        radio1.SelectedValue = roleid;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }

                else
                {
                    //If the user does not exist or a blank value has been entered
                    //Cancel the nextstep redirection and display an error message in a span
                    e.Cancel = true;
                    errorSpan.InnerText = "The username specified is blank or does not belong to PMOD";
                }

                break;
            case "WizardStep3":

                break;
        }
    }
</code></pre>
