DateTime startDate = DateTime.ParseExact(txtstart.Text, "MM/dd/yyyy", null);
DateTime endDate = DateTime.ParseExact(txtend.Text, "MM/dd/yyyy", null);
string n1 = DropDownList2.SelectedItem.Text;
if (DropDownList1.SelectedItem.Text == "Membership")// here you can add selectedindex as well
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ProjectConnectionString"].ToString());
con.Open();
SqlDataAdapter adapter = new SqlDataAdapter("select p.Name,m.* from Membership_det m INNER JOIN Personal_det p ON m.FID= p.FID where m.updateDate between @Start and @End and m.FID =" + n1 + "", con);
adapter.SelectCommand.Parameters.Add("@Start", SqlDbType.Date).Value = startDate;
adapter.SelectCommand.Parameters.Add("@End", SqlDbType.Date).Value = endDate;
DataTable dt = new DataTable();
adapter.Fill(dt);
con.Close();
GridView1.DataSource = dt;
GridView1.DataBind();
// you can use this datatable dt to get that items and use dt to bind the corresponding control.
}
我需要日期验证码。它应该接受 mm/dd/yyyy 格式的日期,否则它应该给出错误消息
aspx 代码如下所示
<asp:TextBox ID="txtstart" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please Enter in the date in MM/dd/yyyy Format" ControlToValidate="txtstart"></asp:RequiredFieldValidator>
<asp:Label ID="Label2" runat="server" Text="End Date:"></asp:Label>
<asp:TextBox ID="txtend" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please Enter in the date in MM/dd/yyyy Format" ControlToValidate="txtend"></asp:RequiredFieldValidator>
它提供调试消息并直接转到代码..运行程序时出现错误..我只想在页面本身中显示错误消息