selection through drop down list

How can i execute a SELECT query from a drop down list. I have a drop down that contains diploma degrees and in my database i have a table called Alumni(Aid,...,Diploma) and a table called Diploma which contains (Did,Diploma) and we have 5 diplomas manually inserted (brevet,bacc2,bachelor,master,doctoral). What i want is to select a diploma from the drop down list so it can end up in Alumni table after i confirm or submit. Here's my code.

Form.aspx:

<form id="form" runat="server" method="post">
<div>
    <table class="style1">
        <tr>
            <td>Diploma:</td>
            <td>
                <asp:DropDownList ID="Diploma" runat="server" AppendDataBoundItems="true" Width="160px">
                <asp:ListItem Text="Select Degree" Value="Select Degree"></asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
      </table>      
<center>
<asp:Button ID="Button1" runat="server" Text="Next" OnClick="Button1_Click" Width="85px" />
</center>
</form>

Form.aspx.cs:

protected void Button_Click(object sender, EventArgs e)
{
    Session["diploma"] = Diploma.SelectedValue;

    if (Status.Text == "1")
    {
        Response.Redirect("C2.aspx");
    }
    else 
    {
        Response.Redirect("C1.aspx");
    }
}
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        if (Session["diploma"] != null &&)
        {
            Diploma.SelectedValue = Session["diploma"].ToString();
        }
    }
}

C1.aspx.cs:

    if (!Page.IsPostBack)
    {
        if (Session["pname"] != null && Session["plastname"] != null && Session["pos"] != null &&
        Session["children"] != null && Session["schoolofchildren"] != null &&
        Session["schoolofchildren1"] != null && Session["schoolofchildren2"] != null)
        {
            PName.Text = Session["pname"].ToString();
            PLastName.Text = Session["plastname"].ToString();
            OldStudent.Text = Session["pos"].ToString();
            Children.Text = Session["children"].ToString();
            SchoolOfChildren.Text = Session["schoolofchildren"].ToString();
            SchoolOfChildren1.Text = Session["schoolofchildren1"].ToString();
            SchoolOfChildren2.Text = Session["schoolofchildren2"].ToString();
        }
    }
}
protected void Button2_Click(object sender, EventArgs e)
{
    Session["pname"] = PName.Text;
    Session["plastname"] = PLastName.Text;
    Session["pos"] = OldStudent.Text;
    Session["children"] = Children.Text;
    Session["schoolofchildren"] = SchoolOfChildren.Text;
    Session["schoolofchildren1"] = SchoolOfChildren1.Text;
    Session["schoolofchildren2"] = SchoolOfChildren2.Text;

    Response.Redirect("Form.aspx");
}
protected void Button3_Click(object sender, EventArgs e)
{
    Session["pname"] = PName.Text;
    Session["plastname"] = PLastName.Text;
    Session["pos"] = OldStudent.Text;
    Session["children"] = Children.Text;
    Session["schoolofchildren"] = SchoolOfChildren.Text;
    Session["schoolofchildren1"] = SchoolOfChildren1.Text;
    Session["schoolofchildren2"] = SchoolOfChildren2.Text;

    Response.Redirect("C2.aspx");
}
protected void Button4_Click(object sender, EventArgs e)
{
    try
    {
        ExecuteInsert1(Session["diploma"].ToString());

        ExecuteInsert2(PName.Text, PLastName.Text, OldStudent.SelectedValue, Children.SelectedValue, SchoolOfChildren.Text, SchoolOfChildren1.Text,
        SchoolOfChildren2.Text);
        Response.Write("Successfully Added!");
        ClearControls(Page);
        Session.Clear();
    }
    catch{}
}
public string GetConnectionString()
{
    return System.Configuration.ConfigurationManager.ConnectionStrings["Champville1ConnectionString"].ConnectionString;
}
public static void ClearControls(Control Parent)
{
    if (Parent is TextBox)
    { (Parent as TextBox).Text = string.Empty; }
    else
    {
        foreach (Control c in Parent.Controls) ClearControls(c);
    }
}
private void ExecuteInsert1(string diploma)
{
    SqlConnection conn = new SqlConnection(GetConnectionString());
    string sql = "INSERT INTO Alumni (Diploma) VALUES " + " (@Diploma)";

    try
    { 
        conn.Open();
        SqlCommand cmd = new SqlCommand(sql, conn);
        SqlParameter[] param = new SqlParameter[1];

        param[0] = new SqlParameter("@Diploma", SqlDbType.NVarChar, 50);

        param[0].Value = diploma;

        for (int i = 0; i < param.Length; i++)
        {
            cmd.Parameters.Add(param[i]);
        }
        cmd.CommandType = CommandType.Text;
        cmd.ExecuteNonQuery();
    }
    catch (System.Data.SqlClient.SqlException ex)
    {
        string msg = "Insert Error:";
        msg += ex.Message;
        throw new Exception(msg);
    }
    finally
    {
        conn.Close();
    }
}
private void ExecuteInsert2(...){}

Answers


Need Your Help

Webservice over SSL endpoint not found with 404

asp.net vb.net web-services security

I've got a webservice up and running and through the browser I can reach it and see it's up and running. Also without https I can make calls to the webservice.

Is there a way to enable autocompletion for PyQt5 with Eclipse Kepler and PyDev 2.8?

eclipse python-2.7 pydev osx-mavericks pyqt5

it seems I can't find a way to enable autocompletion for PyQt5 in Eclipse using PyDev 2.8. I'm running Mac OS 10.9 Mavericks.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.