According to your description, do you want 299 when the record is in 300-599 ,want 599 when record is in 600-899 , want 899 when record is in 900-1199?
If so , you could try the code below.To show the range , I use the method DivideRecords, you could only use the method GetResult.
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(DivideRecords(1000)+";"+"result:"+GetResult(1000));
}
static double GetResult(int number)
{
double count = Math.Ceiling((number+1) * 1.0 / 300); //get how many 300 there are in the number
return (count - 1) * 300 - 1; //get the final result according to how many 300 there are in the number
}
static string DivideRecords(int number)
{
string result = "";
double count = Math.Ceiling(number * 1.0 / 300);
for (int i = 0; i < count-1; i++)
{
string temp = i * 300 + "-" + ((i + 1) * 300 - 1)+",";
result += temp;
}
result += (count - 1) * 300 + "-" + (number-1);
return result;
}
Below is the result.
If it is not your case , please specify your problem and provide the code your have tried,it is not clear about your method Readdata(reponsexml, response).
Best regards,
Ackerly Xu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
16 Points
78 Posts
Total Count divided range calculation in c#
Dec 19, 2018 09:14 AM|jafferpg|LINK
Hi,
I have a task ,which if records contains more than 299, i need to pass the value 299 for each call to the backend
eg : Total Rows = 1000, i need to send each call as 299 i,e(0-299, 300-599, 600-899 ......)
Coding:
output : response. totalrows = 1000;
/// how to write a condition/calculation here
Readdata(reponsexml, response)
return response ; //after that i need to add all the Readdata statement output and bind in final response .
Thanks in advance </div>
Contributor
3500 Points
1300 Posts
Re: Total Count divided range calculation in c#
Dec 20, 2018 02:39 AM|Ackerly Xu|LINK
Hi jafferpg,
According to your description, do you want 299 when the record is in 300-599 ,want 599 when record is in 600-899 , want 899 when record is in 900-1199?
If so , you could try the code below.To show the range , I use the method DivideRecords, you could only use the method GetResult.
Below is the result.
If it is not your case , please specify your problem and provide the code your have tried,it is not clear about your method Readdata(reponsexml, response).
Best regards,
Ackerly Xu
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
16 Points
78 Posts
Re: Total Count divided range calculation in c#
Dec 20, 2018 08:53 AM|jafferpg|LINK
Thanks Ackerly for your response!!
I done by using the below method
if (response.TotalCountRows > 299)
{
for (int i = 300; i <= response.TotalCountRows; i++)
{
search.firstvalue = i;
if ((i + 299) <= response.TotalCountRows)
search.lastvalue = i + 299;
else
search.lastvalue = Convert.ToInt32(response.TotalCountRows);
SplitData(search, messageID, response);
i = i + 299;
}
}