How to highlight today's date row in datagrid when page loaded?
-
I tried that. but i think my syntax is not good. If you can guide me.And also if the current date is not in the list, it should highlight most nearest future date in the datagrid. Thanks, NIKI
HI niki, Send me the code here, i'll try to find the error. If you have not written the code, then i'll give u the code. Thanks Sushant Duggal.
-
HI niki, Send me the code here, i'll try to find the error. If you have not written the code, then i'll give u the code. Thanks Sushant Duggal.
Hi Sushant, The code for comparing the today's date is not here, but other thing which i implemented is here. public void dg_ItemDataBound(object sender, DataGridItemEventArgs e) { if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem) { e.Item.Attributes.Add("onmouseover","this.style.cursor='hand'; this.style.backgroundColor='pink'; "); e.Item.Attributes.Add("onclick","javascript:ShowDetail('"+DataBinder.Eval(e.Item.DataItem,"EVENT_DT")+"');"); ShowDetail is my js function, but it nothing to do with this issue. the full issue is like : I need to highlight today's date if it's available in the datagrid, or nearest future date from today. If you can send some code, that's really helpful for me. I really appreciate your help. Thank you very much Sushant. NIKI
-
Hi Sushant, The code for comparing the today's date is not here, but other thing which i implemented is here. public void dg_ItemDataBound(object sender, DataGridItemEventArgs e) { if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem) { e.Item.Attributes.Add("onmouseover","this.style.cursor='hand'; this.style.backgroundColor='pink'; "); e.Item.Attributes.Add("onclick","javascript:ShowDetail('"+DataBinder.Eval(e.Item.DataItem,"EVENT_DT")+"');"); ShowDetail is my js function, but it nothing to do with this issue. the full issue is like : I need to highlight today's date if it's available in the datagrid, or nearest future date from today. If you can send some code, that's really helpful for me. I really appreciate your help. Thank you very much Sushant. NIKI
HI NIKI, This is what i think u need... Please try this code :
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DateTime dt = Convert.ToDateTime(e.Item.Cells[5].Text);//PUT THE SELL NUMBER WHERE IS THE DATE FIELD if(DateTime.Compare(DateTime.Today, dt) == 0) // this is the current date e.Item.BackColor = Color.Aqua; else if(DateTime.Compare(DateTime.Today, dt) == -1) // this is the future coming dates e.Item.BackColor = Color.Yellow; } }
I hope this helps you:) THanks Sushant Duggal. -
HI NIKI, This is what i think u need... Please try this code :
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DateTime dt = Convert.ToDateTime(e.Item.Cells[5].Text);//PUT THE SELL NUMBER WHERE IS THE DATE FIELD if(DateTime.Compare(DateTime.Today, dt) == 0) // this is the current date e.Item.BackColor = Color.Aqua; else if(DateTime.Compare(DateTime.Today, dt) == -1) // this is the future coming dates e.Item.BackColor = Color.Yellow; } }
I hope this helps you:) THanks Sushant Duggal.Hi Sushant, Thank you very much for help. along with your code, i am adding this two lines. if i dont have today's date or future dates in my datagrid it will highlight the latest past date in datagrid. else if(DateTime.Compare(DateTime.Today, dt) == +1) e.Item.BackColor = Color.red; But, this makes backcolor red for all past dates rows instead of just a single latest past date.(I have at present, no future dates or today's date) I want to highlight only latest past date in datagrid. Any help??? that's really urgent. and, adition to that, it should pass the value for that row as default to the client side javascript function when page load (this should be same for future date, today's date or latest past date).i am trying with 'onload' function, but it's not working. Presently i m passing values on 'onclick' event, as below: e.Item.Attributes.Add("onclick","ShowDetail('"+ DataBinder.Eval(e.Item.DataItem,"TOPIC_DATE")+"');"); any thing you can suggest, it will be very much helpful for me. Thanks you very much again. NIKI
-
Hi Sushant, Thank you very much for help. along with your code, i am adding this two lines. if i dont have today's date or future dates in my datagrid it will highlight the latest past date in datagrid. else if(DateTime.Compare(DateTime.Today, dt) == +1) e.Item.BackColor = Color.red; But, this makes backcolor red for all past dates rows instead of just a single latest past date.(I have at present, no future dates or today's date) I want to highlight only latest past date in datagrid. Any help??? that's really urgent. and, adition to that, it should pass the value for that row as default to the client side javascript function when page load (this should be same for future date, today's date or latest past date).i am trying with 'onload' function, but it's not working. Presently i m passing values on 'onclick' event, as below: e.Item.Attributes.Add("onclick","ShowDetail('"+ DataBinder.Eval(e.Item.DataItem,"TOPIC_DATE")+"');"); any thing you can suggest, it will be very much helpful for me. Thanks you very much again. NIKI
HI Niki, if you want to do that, then you need to add all the rows information of the datagrid in an data table. do one thing, create a datatable(define the datatable globally) , take two columns , one for date and one for row index. do this in ItemDatabound event. then where you are binding the grid, after datagrid.DataBind(), compare and change the color. I hope you got my idea , and this idea works:) Thanks Sushant Duggal.
-
HI Niki, if you want to do that, then you need to add all the rows information of the datagrid in an data table. do one thing, create a datatable(define the datatable globally) , take two columns , one for date and one for row index. do this in ItemDatabound event. then where you are binding the grid, after datagrid.DataBind(), compare and change the color. I hope you got my idea , and this idea works:) Thanks Sushant Duggal.
-
Hi Sushant, This should not work?? if(DateTime.Compare(DateTime.Today, dt) == +1) { e.Item.Attributes.Add("onload","this.style.backgroundColor='red';"); I don't know, i m not sure. Thanks,
hi niki, where r u checking that it is the latest one?????? This will color all the rows. Sushant Duggal.
-
hi niki, where r u checking that it is the latest one?????? This will color all the rows. Sushant Duggal.
-
Hi, I have a datagrid, in which i want to highlight today's date row when that page is loaded. any body have any idea? thanks, NIKI
-
Hi Sushant, I have all the past values at present. so, i want to highlight only the latest past date row. but instead, it's highlighting all past values. I am checking in the item_databound property. Thanks, NIKI
HI Niki, what I wrote in the last thread was to change backcolor of one row only. I got a new and easy Idea. DO one thing, on the page load event, get the max date from the database, then in ItemDataBound compare that date with all the rows, which ever matches, change the backcolor of that row. I think this is really easy:) Thanks Sushant Duggal.