How can I ascend by date in a grid?

enter image description hereI am compiling a grid search list in an asp.net web form. I am using a web service to load a grid. Now, how can I increase the request date?

 gvproposal.DataSource = webservice.EnquiryGetAllLcRequest();
 gvproposal.DataBind();

here i'm just binding a web service now how can i increase the date ??

public IS_LC_REQUEST[] EnquiryGetAllLcRequest();

this is a web service method.

 public class IS_LC_REQUEST : CModelBaseOfIS_LC_REQUEST
    {
        public IS_LC_REQUEST();
        public string BENEFICIARY_ADDRESS { get; set; }
        public string BENEFICIARY_NAME { get; set; }
        public string BRANCH_ID { get; set; }
        public string PORT_OF_SHIPMENT { get; set; }
        public string REQUEST_DATE { get; set; }
        public string REQUEST_ID { get; set; }

    }

Updated:

var arrayOfObjects = IntBankProposal.EnquiryGetAllLcRequest();
var dt = DateTime.Now;
gvproposal.DataSource = arrayOfObjects.OrderBy(load => { if (DateTime.TryParse(load.REQUEST_DATE, out dt)) { return dt; } else { return DateTime.Now.AddYears(-100); } }).ToArray();
gvproposal.DataBind();
+4
source share
4 answers

You can use LINQ to sort the collection that you get from the web service call. Since it REQUEST_DATEhas a string type, you need to convert it to a date using Date.Parse. Make sure you include this namespace in your codeusing System.Linq;

, REQUEST_DATE

var arrayOfObjects =  webservice.EnquiryGetAllLcRequest();
gvproposal.DataSource = arrayOfObjects.OrderBy(e => DateTime.Parse(e.REQUEST_DATE)).ToArray();
gvproposal.DataBind();

REQUEST_DATE,

var arrayOfObjects =  webservice.EnquiryGetAllLcRequest();
var dt = DateTime.MinValue;
DateTime dtNull = DateTime.Now.AddYears(-100);
gvproposal.DataSource = arrayOfObjects.OrderBy(e => { dt = DateTime.MinValue; if(DateTime.TryParse(e.REQUEST_DATE, out dt)) { return dt;} else { return dtNull;}}).ToArray();
gvproposal.DataBind();

, , . .

var arrayOfObjects =  webservice.EnquiryGetAllLcRequest();
var dt = DateTime.MinValue;
 gvproposal.DataSource = arrayOfObjects.OrderBy(e => { dt = DateTime.MinValue; DateTime.TryParse(e.REQUEST_DATE, out dt); return dt;}).ToArray();
gvproposal.DataBind();

, , , , , .

Sort by Date Property for an array of objects using LINQ

+2

OrderBy linq

gvproposal.DataSource = webservice.EnquiryGetAllLcRequest().ToList().OrderBy(x=>x.REQUEST_DATE);
gvproposal.DataBind();
+1

AllowSorting true, OnSorting gridview. OnSorting. .

+1

. , .

<asp:GridView ID="grdHeader" AllowSorting="true" AllowPaging="false" 
    AutoGenerateColumns="false" Width="780" runat="server"  OnSorting="grdHeader_OnSorting" EnableViewState="true">
    <Columns>
        <asp:BoundField DataField="REQUEST_DATE" HeaderText="Date" SortExpression="REQUEST_DATE" />

    </Columns>
</asp:GridView>

By default, gridview is in ascending order. For more information, please visit. GridView Sort: Sort always grows

+1
source

Source: https://habr.com/ru/post/1624039/


All Articles