Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
This is the code and i have error to the bold peace :

var isIdSortable = Convert.ToBoolean(Request["bSortable_1"]);

           var isNameSortable = Convert.ToBoolean(Request["bSortable_2"]);
           var isAddressSortable = Convert.ToBoolean(Request["bSortable_3"]);
           var isTownSortable = Convert.ToBoolean(Request["bSortable_4"]);

           var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
           Func<Order, string> orderingFunction = (c =>  sortColumnIndex == 1 && isIdSortable ? c.OrderID :
             sortColumnIndex == 2 && isNameSortable ? c.CustomerID :
                                                          sortColumnIndex == 3 && isAddressSortable ? c.ShipAddress :
                                                          sortColumnIndex == 4 && isTownSortable ? c.ShipCountry :
                                                          "");



OrderID is INT , CustomerID Adress and Country are string

What I have tried:

i just explained the problem above in the section
Posted
Updated 16-May-17 3:32am

As the error message says, one of the properties you're trying to return is defined as an int, and can't be implicitly converted to a string. I would suspect either OrderID, CustomerID, or both.

You'll need to add a .ToString() call to the int property.
c.OrderID.ToString()

It would probably also be better to move the conditional access outside of the Func, so that you only evaluate it once:
Func<Order, string> orderingFunction;
if (sortColumnIndex == 1 && isIdSortable)
{
    orderingFunction = c => c.OrderID.ToString();
}
else if (sortColumnIndex == 2 && isNameSortable)
{
    orderingFunction = c => c.CustomerID.ToString();
}
else if (sortColumnIndex == 3 && isAddressSortable)
{
    orderingFunction = c => c.ShipAddress;
}
else if (sortColumnIndex == 4 && isTownSortable)
{
    orderingFunction = c => c.ShipCountry; // Really? Is it the town, or the country?
}
else
{
    orderingFunction = c => string.Empty;
}
 
Share this answer
 
use

c.OrderID.ToString()


rather than

c.OrderID
 
Share this answer
 

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