我的DropDowns不会将数据保存在数据库中,但它们有数据。 [英] My DropDowns would not save data in database but they have data.
本文介绍了我的DropDowns不会将数据保存在数据库中,但它们有数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="UserLoginRegister.Registration" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server"> <link href="f1.css" rel="stylesheet" type="text/css" />
<title></title>
<style type="text/css">
.style1 {
width: 99%;
}
.style2 {
height: 25px;
}
.style3 {
width: 272px;
}
.auto-style1 {
font-size: x-large;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<link rel="stylesheet" href="http://localhost:55947/code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="http://jqueryvalidation.org/files/demo/site-demos.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
</head>
<body>
<form id="form2" runat="server">
<div style="height: 648px; width: 545px">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<h2 style="margin-left: 0px"> <span class="auto-style1"> Create Multiverse Tech Account</span></h2>
<br />
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table class="style1">
<tr>
<td class="style3">
<asp:Label ID="Label1" runat="server" Text="FirstName"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtname" runat="server" ValidationGroup="val2" Height="20px" Width="120px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" ControlToValidate="txtname" ErrorMessage="Not Valid " ValidationExpression="^\s*[a-zA-z\s]+\s*$" Display="Dynamic" ForeColor="#FF9900" ValidationGroup="val2">*</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtname" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="Label2" runat="server" Text="LastName"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtLname" runat="server" ValidationGroup="val2" Height="22px" Width="120px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server" ControlToValidate="txtLname" Display="Dynamic" ErrorMessage="RegularExpressionValidator" ForeColor="#FF3399" SetFocusOnError="True" ValidationExpression="^\s*[a-zA-z\s]+\s*$" ValidationGroup="val2">*</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtLname" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="Label3" runat="server" Text="EmailId"></asp:Label>
</td>
<td class="style3">
<asp:UpdatePanel ID="UpdateEmailId" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtemail" runat="server" TextMode="Email" ValidationGroup="val1" Height="22px" Width="120px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtemail" Display="Dynamic" ErrorMessage="Required" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val1">Required</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtemail" ErrorMessage="Not Valid " ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Display="Dynamic" ForeColor="#FF9900" SetFocusOnError="True" ValidationGroup="val1">*</asp:RegularExpressionValidator>
<asp:Button ID="btncheck" runat="server" OnClick="btncheck_Click" Text="Check Availability" ValidationGroup="val1" />
<asp:Label ID="lblNewMessage" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="Label4" runat="server" Text="Password"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtpassword" runat="server" TextMode="Password" ValidationGroup="val2" Height="20px" Width="121px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtpassword" ErrorMessage="Not Valid" ValidationExpression="^.{4,8}$" Display="Dynamic" ForeColor="#FF9900" ValidationGroup="val2">*</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtpassword" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="LGender" runat="server" Text="Gender"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlgen" runat="server" DataTextField="Gender" DataValueField="Gender" Height="21px" Width="120px" OnSelectedIndexChanged="ddlgen_SelectedIndexChanged" ValidationGroup="val2">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="ddlgen" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="LContact" runat="server" Text="ContactNo"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtcontact" runat="server" ValidationGroup="val2" Height="22px" Width="120px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="txtcontact" ErrorMessage="Not Valid" Display="Dynamic" ForeColor="#FF9900" SetFocusOnError="True" ValidationExpression="(\(\d{3}\)|\d{3}-)?\d{10}" ValidationGroup="val2">*</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txtcontact" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="Ldob" runat="server" Text="DateofBirth"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtdob" runat="server" TextMode="date" ValidationGroup="val2" Height="20px" Width="120px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="txtdob" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="Label9" runat="server" Text="CityName"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtcity" runat="server" Height="20px" ValidationGroup="val2" Width="120px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ControlToValidate="txtcity" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="Label10" runat="server" Text="SecurityQuetion"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlsquestion" runat="server" DataTextField="SecurityQuestion" DataValueField="SecurityQuestion" Height="22px" Width="200px" OnSelectedIndexChanged="ddlsquestion_SelectedIndexChanged" ValidationGroup="val2">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="ddlsquestion" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="Label11" runat="server" Text="Security Answer"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtans" runat="server" ValidationGroup="val2" Height="22px" Width="120px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" ControlToValidate="txtans" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="Label6" runat="server" Text="Address"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtaddress" runat="server" ValidationGroup="val2" Height="22px" Width="120px" TextMode="MultiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" ControlToValidate="txtaddress" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="Label7" runat="server" Text="ManagerName"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlmanagername" runat="server" DataTextField="ManagerName" DataValueField="ManagerName" Height="22px" Width="120px" OnSelectedIndexChanged="ddlmanagername_SelectedIndexChanged" ValidationGroup="val2"></asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator14" runat="server" ControlToValidate="ddlmanagername" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator>
</td>
<tr>
<td class="style3">
<asp:Label ID="Label5" runat="server" Text="ManagerEmailId"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlmemail" runat="server" DataTextField="ManagerEmailId" DataValueField="ManagerEmailId" Height="20px" Width="120px" OnSelectedIndexChanged="ddlmemail_SelectedIndexChanged" ValidationGroup="val2"></asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator15" runat="server" ControlToValidate="ddlmemail" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3"> </td>
<td>
<asp:Button ID="btnregistration" runat="server" OnClick="btnregistration_Click"
Text="Registration" Style="height: 26px" ValidationGroup="val2" />
<asp:Label ID="lblmessage" runat="server"></asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<br />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace UserLoginRegister
{
public partial class Registration : System.Web.UI.Page
{
SqlDataReader dr;
SqlConnection con = new SqlConnection("Data Source=MSPLMC0011\\SQLEXPRESS;Initial Catalog=registration;Persist Security Info=True;User ID=sa;Password=multiverse@1");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!(String.IsNullOrEmpty(txtpassword.Text.Trim())))
{
txtpassword.Attributes["value"] = txtpassword.Text;
}
BindGender();
BindSQuestion();
BindManager();
BindMEmail();
}
}
private void BindMEmail()
{
SqlDataAdapter da = new SqlDataAdapter("Select ManagerEmailId from mname", con);
// con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
ddlmemail.DataSource = ds.Tables[0];
ddlmemail.DataBind();
ddlmemail.Items.Insert(0, new ListItem("-Select ManagerId-", ""));
}
private void BindManager()
{
SqlDataAdapter da = new SqlDataAdapter("Select ManagerName from mname", con);
// con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
ddlmanagername.DataSource = ds.Tables[0];
ddlmanagername.DataBind();
ddlmanagername.Items.Insert(0, new ListItem("-Select Manager-", ""));
}
private void BindSQuestion()
{
SqlDataAdapter da = new SqlDataAdapter("Select SecurityQuestion from SecurityQuestion", con);
// con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
ddlsquestion.DataSource = ds.Tables[0];
ddlsquestion.DataBind();
ddlsquestion.Items.Insert(0, new ListItem("-Select Question-", ""));
}
private void BindGender()
{
SqlDataAdapter da = new SqlDataAdapter("Select Gender from gender", con);
// con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
ddlgen.DataSource = ds;
ddlgen.DataBind();
ddlgen.Items.Insert(0, new ListItem("-Select Gender-", ""));
}
protected void btncheck_Click(object sender, EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand("select 1 from registeration where EmailId='" + txtemail.Text + "'", con);
con.Open();
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
lblNewMessage.Visible = true;
lblNewMessage.Text = "EmailId is already exist";
}
else
{
lblmessage.Text = "Ok";
lblNewMessage.Text = "Ok";
}
}
catch (Exception ex)
{
lblNewMessage.Visible = true;
lblNewMessage.Text = ex.Message;
}
}
protected void btnregistration_Click(object sender, EventArgs e)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into registeration(FirstName,LastName,EmailId,Password,Gender,ContactNo,DateofBirth,CityName,SecurityQuestion,SecurityAnswer,Address,ManagerName,ManagerEmailId) values('" + txtname.Text + "','" + txtLname.Text + "','" + txtemail.Text + "','" + txtpassword.Text + "','" + ddlgen.SelectedItem.Text + "'," + txtcontact.Text + "," + txtdob.Text + ",'" + txtcity.Text + "','" + ddlsquestion.SelectedItem.Text + "','" + txtans.Text + "','" + txtaddress.Text + "','" + ddlmanagername.SelectedItem.Text + "','" + ddlmemail.SelectedItem.Text + "')", con);
cmd.ExecuteNonQuery();
Session["EmailId"] = txtemail.Text;
Session["Password"] = txtpassword.Text;
Response.Redirect("Master.aspx");
}
catch (Exception ex)
{
lblmessage.Visible = true;
lblmessage.Text = ex.Message;
}
}
protected void ddlmemail_SelectedIndexChanged(object sender, EventArgs e)
{
//con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select ManagerEmailId from mname", con);
DataSet ds = new DataSet();
da.Fill(ds);
ddlmemail.DataSource = ds.Tables[0];
ddlmemail.DataBind();
ddlmemail.Items.Insert(0, new ListItem("-Select ManagerId-", ""));
}
protected void ddlgen_SelectedIndexChanged(object sender, EventArgs e)
{
//con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select Gender from gender", con);
DataSet ds = new DataSet();
da.Fill(ds);
ddlgen.DataSource = ds.Tables[0];
ddlgen.DataBind();
ddlgen.Items.Insert(0, new ListItem("-Select Gender-", ""));
}
protected void ddlsquestion_SelectedIndexChanged(object sender, EventArgs e)
{
//con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select SecurityQuestion, SecurityID from SecurityQuestion", con);
DataSet ds = new DataSet();
da.Fill(ds);
ddlsquestion.DataSource = ds.Tables[0];
ddlsquestion.DataBind();
ddlsquestion.Items.Insert(0, new ListItem("---Select Question----", ""));
}
protected void ddlmanagername_SelectedIndexChanged(object sender, EventArgs e)
{
//con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select ManagerName from mname", con); //
DataSet ds = new DataSet();
da.Fill(ds);
ddlmanagername.DataSource = ds.Tables[0];
ddlmanagername.DataBind();
ddlmanagername.Items.Insert(0, new ListItem("-Select Manager-", ""));
}
}
}
推荐答案
\" Display=\"Dynamic\" ForeColor=\"#FF9900\" ValidationGroup=\"val2\">*</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID=\"RequiredFieldValidator1\" runat=\"server\" ControlToValidate=\"txtname\" Display=\"Dynamic\" ErrorMessage=\"RequiredFieldValidator\" ForeColor=\"#FF5050\" SetFocusOnError=\"True\" ValidationGroup=\"val2\">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<tdclass=\"style3\">
<asp:Label ID=\"Label2\" runat=\"server\" Text=\"LastName\"></asp:Label>
</td>
<td>
<asp:TextBox ID=\"txtLname\" runat=\"server\" ValidationGroup=\"val2\" Height=\"22px\"Width=\"120px\"></asp:TextBox>
<asp:RegularExpressionValidator ID=\"RegularExpressionValidator6\" runat=\"server\" ControlToValidate=\"txtLname\" Display=\"Dynamic\" ErrorMessage=\"RegularExpressionValidator\" ForeColor=\"#FF3399\" SetFocusOnError=\"True\" ValidationExpression=\"^\s*[a-zA-z\s]+\s*
" Display="Dynamic" ForeColor="#FF9900" ValidationGroup="val2">*</asp:RegularExpressionValidator> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtname" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style3"> <asp:Label ID="Label2" runat="server" Text="LastName"></asp:Label> </td> <td> <asp:TextBox ID="txtLname" runat="server" ValidationGroup="val2" Height="22px" Width="120px"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server" ControlToValidate="txtLname" Display="Dynamic" ErrorMessage="RegularExpressionValidator" ForeColor="#FF3399" SetFocusOnError="True" ValidationExpression="^\s*[a-zA-z\s]+\s*
\" ValidationGroup=\"val2\">*</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID=\"RequiredFieldValidator2\" runat=\"server\" ControlToValidate=\"txtLname\" Display< span class=\"code-keyword\">=\"Dynamic\" ErrorMessage=\"RequiredFieldValidator\" ForeColor=\"#FF5050\" SetFocusOnError=\"True\" ValidationGroup=\"val2\">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class=\"style3\">
<asp:Label ID=\"Label3\" runat=\"server\" Text=\"EmailId\"></asp:Label>
</td>
<td class=\"style3\">
<asp:UpdatePanel ID=\"UpdateEmailId\" runat=\"server\">
<ContentTemplate>
<asp:TextBox ID=\"txtemail\" runat=\"server \" TextMode=\"Email\" ValidationGroup=\"val1\" Height=\"22px\" Width=\"120px\"></asp:TextBox>
<asp:RequiredFieldValidator ID=\"RequiredFieldValidator3\" runat=\"server\" ControlToValidate=\"txtemail\" Display=\"Dynamic\" ErrorMessage=\"Required\" ForeColor=\"#FF5050\" SetFocusOnError=\"True\" ValidationGroup=\"val1\">Required</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID=\"RegularExpressionValidator1\" runat=\"server\" < span class=\"code-attribute\">ControlToValidate=\"txtemail\" ErrorMessage=\"Not Valid \" ValidationExpression=\"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*\" Display=\"Dynamic\" ForeColor=\"#FF9900\" SetFocusOnError=\"True\" ValidationGroup=\"val1\">*</asp:RegularExpressionValidator>
<asp:Button ID=\"btncheck\" runat=\"server\" OnClick=\"btncheck_Click\" Text=\"Check Availability\" ValidationGroup=\"val1\" />
<asp:Label ID=\"lblNewMessage\" runat=\"server\" Text=\"Label\"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td class=\"style3\">
<asp:Label ID=\"Label4\" runat=\"server\" Text=\"Password\"></asp:Label>
</td>
<td>
<asp:TextBox ID=\"txtpassword\" runat=\"server\" TextMode=\"Password\" ValidationGroup=\"val2\" Height=\"20px\" Width=\"121px\"></asp:TextBox>
<asp:RegularExpressionValidator ID=\"RegularExpressionValidator2\" runat=\"server\" ControlToValidate=\"txtpassword\" ErrorMessage=\"Not Valid\" ValidationExpression=\"^.{4,8}
" ValidationGroup="val2">*</asp:RegularExpressionValidator> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtLname" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style3"> <asp:Label ID="Label3" runat="server" Text="EmailId"></asp:Label> </td> <td class="style3"> <asp:UpdatePanel ID="UpdateEmailId" runat="server"> <ContentTemplate> <asp:TextBox ID="txtemail" runat="server" TextMode="Email" ValidationGroup="val1" Height="22px" Width="120px"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtemail" Display="Dynamic" ErrorMessage="Required" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val1">Required</asp:RequiredFieldValidator> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtemail" ErrorMessage="Not Valid " ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Display="Dynamic" ForeColor="#FF9900" SetFocusOnError="True" ValidationGroup="val1">*</asp:RegularExpressionValidator> <asp:Button ID="btncheck" runat="server" OnClick="btncheck_Click" Text="Check Availability" ValidationGroup="val1" /> <asp:Label ID="lblNewMessage" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp:UpdatePanel> </td> </tr> <tr> <td class="style3"> <asp:Label ID="Label4" runat="server" Text="Password"></asp:Label> </td> <td> <asp:TextBox ID="txtpassword" runat="server" TextMode="Password" ValidationGroup="val2" Height="20px" Width="121px"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtpassword" ErrorMessage="Not Valid" ValidationExpression="^.{4,8}
\" Display=\"Dynamic\" ForeColor=\"#FF9900\" ValidationGroup=\"val2\">*</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID=\"RequiredFieldValidator4\" runat=\"server\" ControlToValidate=\"txtpassword\" Display=\"Dynamic\" ErrorMessage=\"RequiredFieldValidator\" ForeColor=\"#FF5050\" SetFocusOnError=\"True\" ValidationGroup=\"val2\">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class=\"style3\">
<asp:Label ID=\"LGender\" runat=\"server\" Text=\"Gender\"></asp:Label>
</td>
<td>
<asp:DropDownList ID=\"ddlgen\" runat=\"server\" DataTextField=\"Gender\" DataValueField=\"Gender\" Height=\"21px\" Width=\"120px\" OnSelectedIndexChanged=\"ddlgen_SelectedIndexChanged\" ValidationGroup=\"val2\">
</asp:DropDownList>
<asp:RequiredFieldValidator ID=\"RequiredFieldValidator5\" runat=\"server\" ControlToValidate=\"ddlgen\" Display=\"Dynamic\" ErrorMessage=\"RequiredFieldValidator\" ForeColor=\"#FF5050\" SetFocusOnError=\"True\" ValidationGroup=\"val2\">Required</asp:RequiredFieldValidator >
</td>
</tr>
<tr>
<td class=\"style3\">
<asp:Label ID=\"LContact\" runat=\"server\" Text=\"ContactNo\"></asp:Label>
</td>
<td>
<asp:TextBox ID=\"txtcontact\" runat=\"server\" ValidationGroup=\"val2\" Height=\"22px\" Width=\"120px\"></asp:TextBox>
<asp:RegularExpressionValidator ID=\"RegularExpressionValidator3\" runat=\"server\" ControlToValidate=\"txtcontact\" ErrorMessage=\"Not Valid\" Display=\"Dynamic\" ForeColor=\"#FF9900\" SetFocusOnError=\"True\" ValidationExpression=\"(\(\d{3}\)|\d{3}-)?\d{10}\" ValidationGroup=\"val2\">*</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID=\"RequiredFieldValidator6\" runat=\"server\" ControlToValidate=\"txtcontact\" Display=\"Dynamic\" ErrorMessage=\"RequiredFieldValidator\" ForeColor=\"#FF5050\" SetFocusOnError=\"True\" ValidationGroup=\"val2\">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class=\"style3\">
<asp:Label ID=\"Ldob\" runat=\"server\" Text=\"DateofBirth\"></asp:Label>
</td>
<td>
<asp:TextBox ID=\"txtdob\" runat=\"server\" TextMode=\"date\" ValidationGroup=\"val2\" Height=\"20px\" Width=\"120px\"></asp:TextBox>
<asp:RequiredFieldValidator ID=\"RequiredFieldValidator7\" runat=\"server\" ControlToValidate=\"txtdob\" Display=\"Dynamic\" ErrorMessage=\"RequiredFieldValidator\" ForeColor=\"#FF5050\" SetFocusOnError=\"True\" ValidationGroup=\"val2\">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class=\"style3\">
<asp:Label ID=\"Label9\" runat=\"server\" Text=\"CityName\"></asp:Label>
</td>
<td >
<asp:TextBox ID=\"txtcity\" runat=\"server\" Height=\"20px\" ValidationGroup=\"val2\" Width=\"120px\"></asp:TextBox>
<asp:RequiredFieldValidator ID=\"RequiredFieldValidator10\" runat=\"server\" ControlToValidate=\"txtcity\" Display=\"Dynamic\" ErrorMessage=\"RequiredFieldValidator\" ForeColor=\"#FF5050\" SetFocusOnError=\"True\" ValidationGroup=\"val2\">Required</asp:RequiredFieldValidator>
</td>
< /tr>
<tr>
<td class=\"style3\">
<asp:Label ID=\"Label10\" runat=\"server\" Text=\"SecurityQuetion\"></asp:Label>
</td>
<td>
<asp:DropDownList ID=\"ddlsquestion\" runat=\"server\" DataTextField=\"SecurityQuestion\" DataValueField=\"SecurityQuestion\" Height=\"22px\" Width=\"200px\" OnSelectedIndexChanged=\"ddlsquestion_SelectedIndexChanged\" Validati onGroup=\"val2\">
</asp:DropDownList>
<asp:RequiredFieldValidator ID=\"RequiredFieldValidator11\" runat=\"server\" ControlToValidate=\"ddlsquestion\" Disp lay=\"Dynamic\" ErrorMessage=\"RequiredFieldValidator\" ForeColor=\"#FF5050\" SetFocusOnError=\"True\" ValidationGroup=\"val2\">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class=\"style3\">
<asp:Label ID=\"Label11\" runat=\"server\" Text=\"Security Answer\"></asp:Label>
</td>
<td>
<asp:TextBox ID=\"txtans\" runat=\"server\" ValidationGroup=\"val2\" Height=\"22px\" Width=\"120px\"></asp:TextBox>
<asp:RequiredFieldValidator< span class=\"code-attribute\"> ID=\"RequiredFieldValidator12\" runat=\"server\" ControlToValidate=\"txtans\" Display=\"Dynamic\" ErrorMessage=\"RequiredFieldValidator\" ForeColor=\"#FF5050\" SetFocusOnError=\"True\" ValidationGroup=\"val2\">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
< ;td class=\"style3\">
<asp:Label ID=\"Label6\" runat=\"server\" Text=\"Address\"></asp:Label>
</td>
<td>
<asp:TextBox ID=\"txtaddress\" runat=\"server\" ValidationGroup=\"val2\" Height=\"22px\" Width=\"120px\" TextMode=\"MultiLine\"></asp:TextBox>
<asp:RequiredFieldValidator ID=\"RequiredFieldValidator13\" runat=\"server\" ControlToValidate=\"txtaddress\" Display=\"Dynamic\" ErrorMessage=\"RequiredFieldValidator\" ForeColor=\"#FF5050\" SetFocusOnError=\"True\" ValidationGroup=\"val2\">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class=\"style3\">
<asp:Label ID=\"Label7\" runat=\"server\" Text=\"ManagerName\"></asp:Label>
</td>
<td>
<asp:DropDownList ID=\"ddlmanagername\" runat=\"server\" DataTextField=\"ManagerName\" DataValueField=\"ManagerName\" Height=\"22px\" Width=\"120px\" OnSelectedIndexChanged=\"ddlmanagername_SelectedIndexChanged\" ValidationGroup=\"val2\"></asp:DropDownList>
<asp:RequiredFieldValidator ID=\"RequiredFieldValidator14\" runat=\"server\" ControlToValidate=\"ddlmanagername\" Display=\"Dynamic\" ErrorMessage=\"RequiredFieldValidator\" ForeColor=\"#FF5050\" SetFocusOnError=\"True\" ValidationGroup=\"val2\">Required</asp:RequiredFieldValidator>
</td>
<tr>
<td class=\"style3\">
<asp:Label ID=\"Label5\" runat=\"server\" Text=\"ManagerEmailId\"></asp:Label>
</td>
<td>
<asp:DropDownList ID=\"ddlmemail\" runat=\"server\" DataTextField=\"ManagerEmailId\" DataValueField=\"ManagerEmailId\" Height=\"20px\" Width=\"120px\" OnSelectedIndexChanged=\"ddlmemail_SelectedIndexChanged\" ValidationGroup=\"val2\"></asp:DropDownList>
<asp:RequiredFieldValidator ID=\"RequiredFieldValidator15\" runat=\"server\" ControlToValidate=\"ddlmemail\" Display=\"Dynamic\" ErrorMessage=\"RequiredFieldValidator\" ForeColor=\"#FF5050\" SetFocusOnError=\"True\" ValidationGroup=\"val2\">Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class=\"style3\"> </td>
<td>
<asp:Button ID=\"btnregistration\" runat=\"server\" OnClick=\"btnregistration_Click\"
< span class =code-attribute> Text=\"Registration\" Style=\"height: 26px\" ValidationGroup=\"val2\" />
<asp:Label ID=\"lblmessage\" runat=\"server\"></asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<br />
</div>
</form>
</body>
</html>
" Display="Dynamic" ForeColor="#FF9900" ValidationGroup="val2">*</asp:RegularExpressionValidator> <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtpassword" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style3"> <asp:Label ID="LGender" runat="server" Text="Gender"></asp:Label> </td> <td> <asp:DropDownList ID="ddlgen" runat="server" DataTextField="Gender" DataValueField="Gender" Height="21px" Width="120px" OnSelectedIndexChanged="ddlgen_SelectedIndexChanged" ValidationGroup="val2"> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="ddlgen" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style3"> <asp:Label ID="LContact" runat="server" Text="ContactNo"></asp:Label> </td> <td> <asp:TextBox ID="txtcontact" runat="server" ValidationGroup="val2" Height="22px" Width="120px"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="txtcontact" ErrorMessage="Not Valid" Display="Dynamic" ForeColor="#FF9900" SetFocusOnError="True" ValidationExpression="(\(\d{3}\)|\d{3}-)?\d{10}" ValidationGroup="val2">*</asp:RegularExpressionValidator> <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txtcontact" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style3"> <asp:Label ID="Ldob" runat="server" Text="DateofBirth"></asp:Label> </td> <td> <asp:TextBox ID="txtdob" runat="server" TextMode="date" ValidationGroup="val2" Height="20px" Width="120px"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="txtdob" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style3"> <asp:Label ID="Label9" runat="server" Text="CityName"></asp:Label> </td> <td> <asp:TextBox ID="txtcity" runat="server" Height="20px" ValidationGroup="val2" Width="120px"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ControlToValidate="txtcity" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style3"> <asp:Label ID="Label10" runat="server" Text="SecurityQuetion"></asp:Label> </td> <td> <asp:DropDownList ID="ddlsquestion" runat="server" DataTextField="SecurityQuestion" DataValueField="SecurityQuestion" Height="22px" Width="200px" OnSelectedIndexChanged="ddlsquestion_SelectedIndexChanged" ValidationGroup="val2"> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="ddlsquestion" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style3"> <asp:Label ID="Label11" runat="server" Text="Security Answer"></asp:Label> </td> <td> <asp:TextBox ID="txtans" runat="server" ValidationGroup="val2" Height="22px" Width="120px"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" ControlToValidate="txtans" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style3"> <asp:Label ID="Label6" runat="server" Text="Address"></asp:Label> </td> <td> <asp:TextBox ID="txtaddress" runat="server" ValidationGroup="val2" Height="22px" Width="120px" TextMode="MultiLine"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" ControlToValidate="txtaddress" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style3"> <asp:Label ID="Label7" runat="server" Text="ManagerName"></asp:Label> </td> <td> <asp:DropDownList ID="ddlmanagername" runat="server" DataTextField="ManagerName" DataValueField="ManagerName" Height="22px" Width="120px" OnSelectedIndexChanged="ddlmanagername_SelectedIndexChanged" ValidationGroup="val2"></asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidator14" runat="server" ControlToValidate="ddlmanagername" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator> </td> <tr> <td class="style3"> <asp:Label ID="Label5" runat="server" Text="ManagerEmailId"></asp:Label> </td> <td> <asp:DropDownList ID="ddlmemail" runat="server" DataTextField="ManagerEmailId" DataValueField="ManagerEmailId" Height="20px" Width="120px" OnSelectedIndexChanged="ddlmemail_SelectedIndexChanged" ValidationGroup="val2"></asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidator15" runat="server" ControlToValidate="ddlmemail" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="#FF5050" SetFocusOnError="True" ValidationGroup="val2">Required</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style3"> </td> <td> <asp:Button ID="btnregistration" runat="server" OnClick="btnregistration_Click" Text="Registration" Style="height: 26px" ValidationGroup="val2" /> <asp:Label ID="lblmessage" runat="server"></asp:Label> </td> </tr> </table> </ContentTemplate> </asp:UpdatePanel> <br /> </div> </form> </body> </html>
$b$ b
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace UserLoginRegister
{
public partial class Registration : System.Web.UI.Page
{
SqlDataReader dr;
SqlConnection con = new SqlConnection("Data Source=MSPLMC0011\\SQLEXPRESS;Initial Catalog=registration;Persist Security Info=True;User ID=sa;Password=multiverse@1");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!(String.IsNullOrEmpty(txtpassword.Text.Trim())))
{
txtpassword.Attributes["value"] = txtpassword.Text;
}
BindGender();
BindSQuestion();
BindManager();
BindMEmail();
}
}
private void BindMEmail()
{
SqlDataAdapter da = new SqlDataAdapter("Select ManagerEmailId from mname", con);
// con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
ddlmemail.DataSource = ds.Tables[0];
ddlmemail.DataBind();
ddlmemail.Items.Insert(0, new ListItem("-Select ManagerId-", ""));
}
private void BindManager()
{
SqlDataAdapter da = new SqlDataAdapter("Select ManagerName from mname", con);
// con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
ddlmanagername.DataSource = ds.Tables[0];
ddlmanagername.DataBind();
ddlmanagername.Items.Insert(0, new ListItem("-Select Manager-", ""));
}
private void BindSQuestion()
{
SqlDataAdapter da = new SqlDataAdapter("Select SecurityQuestion from SecurityQuestion", con);
// con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
ddlsquestion.DataSource = ds.Tables[0];
ddlsquestion.DataBind();
ddlsquestion.Items.Insert(0, new ListItem("-Select Question-", ""));
}
private void BindGender()
{
SqlDataAdapter da = new SqlDataAdapter("Select Gender from gender", con);
// con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
ddlgen.DataSource = ds;
ddlgen.DataBind();
ddlgen.Items.Insert(0, new ListItem("-Select Gender-", ""));
}
protected void btncheck_Click(object sender, EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand("select 1 from registeration where EmailId='" + txtemail.Text + "'", con);
con.Open();
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
lblNewMessage.Visible = true;
lblNewMessage.Text = "EmailId is already exist";
}
else
{
lblmessage.Text = "Ok";
lblNewMessage.Text = "Ok";
}
}
catch (Exception ex)
{
lblNewMessage.Visible = true;
lblNewMessage.Text = ex.Message;
}
}
protected void btnregistration_Click(object sender, EventArgs e)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into registeration(FirstName,LastName,EmailId,Password,Gender,ContactNo,DateofBirth,CityName,SecurityQuestion,SecurityAnswer,Address,ManagerName,ManagerEmailId) values('" + txtname.Text + "','" + txtLname.Text + "','" + txtemail.Text + "','" + txtpassword.Text + "','" + ddlgen.SelectedItem.Text + "'," + txtcontact.Text + "," + txtdob.Text + ",'" + txtcity.Text + "','" + ddlsquestion.SelectedItem.Text + "','" + txtans.Text + "','" + txtaddress.Text + "','" + ddlmanagername.SelectedItem.Text + "','" + ddlmemail.SelectedItem.Text + "')", con);
cmd.ExecuteNonQuery();
Session["EmailId"] = txtemail.Text;
Session["Password"] = txtpassword.Text;
Response.Redirect("Master.aspx");
}
catch (Exception ex)
{
lblmessage.Visible = true;
lblmessage.Text = ex.Message;
}
}
protected void ddlmemail_SelectedIndexChanged(object sender, EventArgs e)
{
//con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select ManagerEmailId from mname", con);
DataSet ds = new DataSet();
da.Fill(ds);
ddlmemail.DataSource = ds.Tables[0];
ddlmemail.DataBind();
ddlmemail.Items.Insert(0, new ListItem("-Select ManagerId-", ""));
}
protected void ddlgen_SelectedIndexChanged(object sender, EventArgs e)
{
//con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select Gender from gender", con);
DataSet ds = new DataSet();
da.Fill(ds);
ddlgen.DataSource = ds.Tables[0];
ddlgen.DataBind();
ddlgen.Items.Insert(0, new ListItem("-Select Gender-", ""));
}
protected void ddlsquestion_SelectedIndexChanged(object sender, EventArgs e)
{
//con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select SecurityQuestion, SecurityID from SecurityQuestion", con);
DataSet ds = new DataSet();
da.Fill(ds);
ddlsquestion.DataSource = ds.Tables[0];
ddlsquestion.DataBind();
ddlsquestion.Items.Insert(0, new ListItem("---Select Question----", ""));
}
protected void ddlmanagername_SelectedIndexChanged(object sender, EventArgs e)
{
//con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select ManagerName from mname", con); //
DataSet ds = new DataSet();
da.Fill(ds);
ddlmanagername.DataSource = ds.Tables[0];
ddlmanagername.DataBind();
ddlmanagername.Items.Insert(0, new ListItem("-Select Manager-", ""));
}
}
}
这篇关于我的DropDowns不会将数据保存在数据库中,但它们有数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文