hiii..我正在做一个调查项目。我有一个文本框和两个 ajax 日历扩展器。我想使用调查名称作为会话。怎么做??我不熟悉会话。谁能帮帮我???
protected void Button1_Click(object sender, EventArgs e)
{
string strcon;
strcon = ConfigurationManager.ConnectionStrings["SurveyConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strcon);
SqlCommand com2 = new SqlCommand(strcon);
com2.Connection = con;
con.Open();
com2.CommandText = "insert into SurveyMaster1(SurveyName,DateCreated,ExpiredDate) VALUES(@SurveyName,@DateCreated,@ExpiredDate)";
com2.Parameters.AddWithValue("@SurveyName", txtSurveyName.Text);
com2.Parameters.AddWithValue("@DateCreated", txtCreaDate.Text);
com2.Parameters.AddWithValue("@ExpiredDate", txtExDate.Text);
com2.ExecuteNonQuery();
Response.Write("Inserted Successfully");
con.Close();
Response.Redirect("Questions.aspx");
}
}
asp代码:
<asp:Panel ID="Panel1" runat="server">
<asp:Label ID="Label1" runat="server" ></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Survey Name"></asp:Label>
<asp:Label ID="Label4" runat="server" Text="Expired Date"></asp:Label>
<asp:TextBox ID="txtSurveyName" runat="server"></asp:TextBox>
<asp:TextBox ID="txtCreaDate" runat="server" ></asp:TextBox>
<asp:CalendarExtender ID="txtCreaDate_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txtCreaDate">
</asp:CalendarExtender>
<asp:TextBox ID="txtExDate" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="txtExDate_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txtExDate">
</asp:CalendarExtender>
<asp:Button ID="Button1" runat="server" Text="SAVE" onclick="Button1_Click" />
<asp:RequiredFieldValidator ID="reqFieldSurvey" runat="server"
ControlToValidate="txtSurveyName" ErrorMessage="* Enter Survey Name"
style="z-index: 1; left: 458px; top: 99px; position: absolute; bottom: 286px"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="reqCreDate" runat="server"
ControlToValidate="txtCreaDate" ErrorMessage="* Select Date" > </asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="reqExpDate" runat="server"
ControlToValidate="txtExDate" ErrorMessage="* Select Date"></asp:RequiredFieldValidator>
</asp:Panel>