Hi, Date Filter in ASP.NET GridView
Step 1. In SP select Statement get as Date
e.g. CONVERT(date, CC.DeliveryDate,103) AS DeliveryDate,
step 2.
At first time don filter with where conditions and second time filter like below
where (@DeliveryDate IS NULL OR CONVERT(varchar(10), CC.DeliveryDate, 103) LIKE CONVERT(varchar(10), @DeliveryDate, 103) + '%')
Step 3. While Passing pass as datetime like @DeliveryDate Datetime=null
Step 4. From Front end Pass date as with datetime datatype
If Not IsNothing(ViewState(DeliveryDate)) Then
cmd.Parameters.Add(@DeliveryDate, SqlDbType.DateTime).Value = ViewState(DeliveryDate)
Else
cmd.Parameters.Add(@DeliveryDate, SqlDbType.DateTime).Value = DBNull.Value
End If
Step 5 In grid template column set date format as below text='<%# Eval("DeliveryDate", "{0:dd/MM/yyyy}") %>'
<asp:TemplateField HeaderText="Delivery Date" ItemStyle-HorizontalAlign="Center" SortExpression="DeliveryDate">
<ItemTemplate>
<asp:Label ID="lblDeliveryDate" runat="server" text='<%# Eval("DeliveryDate", "{0:dd/MM/yyyy}") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Step 1. In SP select Statement get as Date
e.g. CONVERT(date, CC.DeliveryDate,103) AS DeliveryDate,
step 2.
At first time don filter with where conditions and second time filter like below
where (@DeliveryDate IS NULL OR CONVERT(varchar(10), CC.DeliveryDate, 103) LIKE CONVERT(varchar(10), @DeliveryDate, 103) + '%')
Step 3. While Passing pass as datetime like @DeliveryDate Datetime=null
Step 4. From Front end Pass date as with datetime datatype
If Not IsNothing(ViewState(DeliveryDate)) Then
cmd.Parameters.Add(@DeliveryDate, SqlDbType.DateTime).Value = ViewState(DeliveryDate)
Else
cmd.Parameters.Add(@DeliveryDate, SqlDbType.DateTime).Value = DBNull.Value
End If
Step 5 In grid template column set date format as below text='<%# Eval("DeliveryDate", "{0:dd/MM/yyyy}") %>'
<asp:TemplateField HeaderText="Delivery Date" ItemStyle-HorizontalAlign="Center" SortExpression="DeliveryDate">
<ItemTemplate>
<asp:Label ID="lblDeliveryDate" runat="server" text='<%# Eval("DeliveryDate", "{0:dd/MM/yyyy}") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
WcongniFsuppbu Jeff Diaz https://wakelet.com/wake/Nq5weXQmLPmp7_GzLdrzf
ReplyDeletetriferambuy