How to gray out data which is before start time in list view of asp.net Web forms?


I am showing the list of restaurants in the listview, in this list, I have restaurant's start time and end time, So I want o to disable those restaurant's which is listed on the list, before start time , so that's user can't click on them or view them, in other words, gray out the restaurant's which isn't opened yet

Here is my current code:- restaurants.aspx

 

<asp:ListView ID="restlist" runat="server" EnableTheming="False">
<ItemTemplate>
<div class="delivery">

<p> Delivery Charges : RS <%#Eval("Column1")%> </p>

<p> Delivery Charges : RS <%#Eval("column2")%> </p>

<p>Delivered in <%#Eval("column3")%></p>

</ItemTemplate>

</ListView>

restaurants.cs.aspx (Code behind)

rest = "(select * from restaurants)";

Dataset ds=new Dataset();

string s=rest;

ds = con.get(s);

if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
restlist.DataSource = ds.Tables[0];
restlist.DataBind();
}
else
{
restlist.DataSource = null;
restlist.DataBind();
}
}

else
{
restlist.DataSource = null;
restlist.DataBind();
}

 

Asked by:- RameshwarLate
0
: 2047 At:- 9/7/2017 10:30:53 AM
listview asp.net web-forms gray-out-data







1 Answers
profileImage Answered by:- vikas_jk

You can Gray out restaurant name by comparing its start time with current datetime, using the Eval function

Your code would be something like this

<asp:ListView ID="restlist" runat="server" EnableTheming="False">
<ItemTemplate>
<div class="delivery">
 <span runat="server" style='<%# (DateTime)Eval("DateTimeStart") < DateTime.Now ? "background-color:gray": "" %>'>
        
            Gray Out restraunt Name
       
        </span>
<p> Delivery Charges : RS <%#Eval("Column1")%> </p>

<p> Delivery Charges : RS <%#Eval("column2")%> </p>

<p>Delivered in <%#Eval("column3")%></p>

</ItemTemplate>

</ListView>

Remember in the above code I have compared Date and time both, you can compare just date's or time depending on your need.

0
At:- 9/7/2017 2:16:29 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use