Hi
In below code i want if Next Action Date is not null or '' & Next ActionDate <= Current Date then No Of Days should be calculated
Thanks
Hi
In below code i want if Next Action Date is not null or '' & Next ActionDate <= Current Date then No Of Days should be calculated
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Prasad RaveendranPosted Jun 18, 2023, 3:27 PM
I'm wondering , how this method leads to performance impact? If I'm not wrong, you will not be populating 1000 of records into grid or whatever tabular controls you are going to choose.
if you are replacing with any other control, you can still go ahead and use the same method from code behind. However, if there is a valid reason(for an instance: business requirement), certainly it would be a change.
My personal opinion, should not add any logic in presentation logic.
However, its all depends on how your architecture decision.
Tuhin PaulPosted Jun 18, 2023, 3:16 PM
The code assumes that the
Tuhin PaulPosted Jun 18, 2023, 3:16 PM
The code mixes business logic with presentation logic by including the GetNumberOfDays method directly in the code-behind file. This can make the code less maintainable, especially as the application grows and more functionality is added.
Tuhin PaulPosted Jun 18, 2023, 3:16 PM
The code calls the GetNumberOfDays method for each item bound to the control. Depending on the size of the data source and the frequency of updates, this could result in a performance impact.
Prasad RaveendranPosted Jun 18, 2023, 2:04 AM
To achieve the desired behavior, you can use an inline code block within the
Textattribute of thecontrol. Here's an updated version of the code:In the code-behind file (e.g., .aspx.cs or .aspx.vb), define a method called
GetNumberOfDaysthat calculates the number of days if the conditions are met:In this code, the
GetNumberOfDaysmethod checks if thenextActionDateis not null, notDBNull.Value, and not an empty string. If these conditions are met and theNextActionDateis less than or equal to the current date (DateTime.Now), it calculates the difference in days using aTimeSpanobject and returns the number of days as a string. Otherwise, it returns an empty string.Note that the
Evalmethod is used to evaluate the value of theNextActionDatefrom the data source binding context. Make sure that the data source is properly configured to provide the correct value forNextActionDate.Mohamed Azarudeen ZPosted Jun 17, 2023, 4:11 PM
Hi Ramco kindly check the upddated code below.
In this code, we added a condition using the ternary operator (
? :) to check if theNextActionDateis not null, not empty, and if it is less than or equal to the current date. If the condition is true, it calculates the number of days betweenNextActionDateand the current date using(DateTime.Now - Convert.ToDateTime(Eval("NextActionDate"))).Duration().Daysand converts it to a string. Otherwise, it assigns an empty string.Make sure to replace the
Eval("NextActionDate")with the appropriate data binding expression based on your actual implementation.