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();
}
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.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly