Hello Sir,
Acutally i have added a GridView on my webform and two text box's with having asp:calender extensions, button as well. I have one table in my database with column name 'Time'(datetime) with having some dates.
I need any one can search in between the selected dates, but i am facing a problem, if i select the excat year what i have in my database table then only i get my result into the Gridview otherwise i am getting an error........
protected void btnAdminSearchDate_Click(object sender, EventArgs e)
Line 838: {
Line 839: DateTime dt1 = Convert.ToDateTime(FromDate.Text);
Line 840:DateTime dt2 = Convert.ToDateTime(UptoDate.Text);
My ASPX page code for that part is as follows...
<div style="position:relative; right:0px; ">
<asp:Label ID="Label4" runat="server" Text="From" ForeColor="#E68A00" Font-Size="Larger" Font-Bold="true"></asp:Label>
<asp:TextBox ID="FromDate" Height="35px" BorderWidth="2px" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="first" TargetControlID="FromDate" runat="server" Format="dd/MM/yyyy" ></asp:CalendarExtender>
<asp:Label ID="Label74" runat="server" Text="To" ForeColor="#E68A00" Font-Size="Larger" Font-Bold="true"></asp:Label>
<asp:TextBox ID="UptoDate" Height="35px" BorderWidth="2px" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtender2" TargetControlID="UptoDate" runat="server" Format="dd/MM/yyyy" ></asp:CalendarExtender>
<asp:LinkButton ID="btnAdminSearchDate" Width="100px" Height="33px" BackColor="#E68A00" ForeColor="White" Font-Bold="true" runat="server" Text="Search" OnClick="btnAdminSearchDate_Click" style=" text-decoration:none; text-align:center; " />
</div>
My .cs code is as follows...
protected void btnAdminSearchDate_Click(object sender, EventArgs e)
{
DateTime dt1 = Convert.ToDateTime(FromDate.Text);
DateTime dt2 = Convert.ToDateTime(UptoDate.Text);
try
{
if (FromDate.Text == "" && UptoDate.Text == "")
{
Label75.Visible = true;
}
else
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["freeonlinedata"].ConnectionString);
conn.Open();
SqlDataAdapter dasearch = new SqlDataAdapter("select * from tblRGPVPaper where Time Between '" + dt1 + "' and '" + dt2 + "'", conn);
DataSet dssearch = new DataSet();
dasearch.Fill(dssearch, "tblRGPVPaper");
if (dssearch.Tables["tblRGPVPaper"].Rows.Count > 0)
{
GridView1.DataSource = dssearch.Tables["tblRGPVPaper"];
GridView1.DataBind();
}
else
{
System.Windows.Forms.MessageBox.Show("Records are not available...");
}
}
}
catch
{
throw;
}
}
So please help me to resolve it....
Thanks in advance!!!!