Click here to Skip to main content
15,890,399 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,

Am Fresher to Asp.net, Please can you Clear/Solve my doubt.

I have a GRIDVIEW on My WEBFORM.
I have Displayed Data in GRidview using SQlserver 2005....its fine.

In this GRIDVIEW I have two Columns with Dates..... VALID FROM and VALID TO.

Valid from is cell[4] and Valid to is Cell[5]

Suppose if the date VALID FROM is Greater than VALID TO..... Valid From cell should be blink.

Please can u show me how to do this.

Thanks in Advance.
Posted
Comments
ZurdoDev 19-Jun-12 8:14am    
You will need to apply CSS styles to the cell using an event such as the RowDataBound. I'd suggest looking on google for an example.

1 solution

suppose you are having two labels in gridview as :
XML
<asp:TemplateField HeaderText="FromDate">
                    <ItemTemplate>
                        <asp:Label ID="lblFromDate" runat="server" Text='<%#Eval("fromdate") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="ToDate">
                    <ItemTemplate>
                        <asp:Label ID="lblToDate" runat="server" Text='<%#Eval("todate") %>'></asp:Label></ItemTemplate>
                </asp:TemplateField>



Then you compare the two dates in RowDataBound Event using DateTime.Compare function such as:
C#
if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label fromdate = (Label)e.Row.FindControl("lblFromDate");
            Label todate = (Label)e.Row.FindControl("lblToDate");
            DateTime fdate = Convert.ToDateTime(fromdate.Text);
            DateTime tdate = Convert.ToDateTime(todate.Text);
            
            if (DateTime.Compare(fdate, tdate) > 0)
            {
                fromdate.Style.Add("text-decoration", "blink");
            }.......


get more infomation about DateTime.Compare from google.
Hope this helps.
 
Share this answer
 
Comments
Prosan 29-Jun-12 5:04am    
my 5
[no name] 29-Jun-12 5:58am    
but it works on some browser not for all
Vani Kulkarni 29-Jun-12 5:22am    
My 5 too!
bhagirathimfs 29-Jun-12 5:38am    
5*
Sandeep Mewara 30-Jun-12 6:36am    
Good answer. 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900