CREATE procedure [dbo].[date_sp_new]
(
@fromdate as varchar(50),
@todate as varchar(50)
)
AS
declare @date1 as datetime
declare @date2 as datetime
select @date1 =  convert(varchar(50), @fromdate,120)
select @date2 =   convert(varchar(50), @todate,120)
begin
if (@date1 = '' or @date2 = '')

select * from mkt_contact

else if(@date1 != ''and @date2 = '')

select * from mkt_contact where CONVERT(CHAR(10),contact_addeddate_dt,120) >= @date1

else if(@date1 = '' and  @date2 != '')

select * from mkt_contact where CONVERT(CHAR(10),contact_addeddate_dt,120) <= @date2 

else if(@date1 != ''and @date2 != '')

select * from mkt_contact where CONVERT(CHAR(10),contact_addeddate_dt,120) between @date1 and @date2

End 

and
the aspx page code is

//try
    //    {

    //          SqlDataSource sds_confirm_date = new SqlDataSource();
    //           sds_confirm_date.ConnectionString = ConfigurationManager.ConnectionStrings["BTI_NEWConnectionString"].ToString();
    //           sds_confirm_date.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
    //           sds_confirm_date.SelectCommand = "[date_sp_new]";
    //            //sds_confirm_date.SelectParameters.Add(new Parameter("fromdate", System.TypeCode.String, TextBox_addedDate_from.Text));
    //            //sds_confirm_date.SelectParameters.Add(new Parameter("todate", System.TypeCode.String, TextBox_addedDate_to.Text));

    //            //String dtfromdate = null;
    //            //if (TextBox_addedDate_from.Text != string.Empty)
    //            //    dtfromdate = TextBox_addedDate_from.Text;

    //            //String dttodate = null;
    //            //if (TextBox_addedDate_to.Text != string.Empty)
    //            //    dttodate = TextBox_addedDate_to.Text;
    //            //if (TextBox_addedDate_from.Text == "")
    //            //{
    //            //    sds_confirm_date.SelectParameters.Add("fromdate", System.TypeCode.DBNull, null);
    //            //}
    //            //else
    //            //{
    //            //    sds_confirm_date.SelectParameters.Add(new Parameter("fromdate", System.TypeCode.String, TextBox_addedDate_from.Text));
    //            //}
    //            //if (TextBox_addedDate_to.Text == "")
    //            //{
    //            //    sds_confirm_date.SelectParameters.Add("todate", System.TypeCode.DBNull, null);
    //            //}
    //            //else
    //            //{
    //            //    sds_confirm_date.SelectParameters.Add(new Parameter("todate", System.TypeCode.String, TextBox_addedDate_to.Text));
    //            //}
    //            //


    //            sds_confirm_date.SelectParameters.Add(new Parameter("fromdate", System.TypeCode.String, TextBox_addedDate_from.Text));
    //            sds_confirm_date.SelectParameters.Add(new Parameter("todate", System.TypeCode.String, TextBox_addedDate_to.Text));
    //            GridView1.DataSource = sds_confirm_date;
    //            GridView1.DataBind();
    //        }


    //    catch (Exception ex)
    //    {
    //        Label1.Text=ex.Message;
    //
}

but not getting the result for when blank textbox values are pass to store prcedure

Since you didn't use code tags, that's really hard to read and why would you include commented out code?

please don't use unnecessary comments.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.