c# - GridObjectDataSource DataTable Sorting with parameters -
my trouble not know howto pass events sort datatable. have listed .aspx page, , flow of behind .cs file bindthrottles function. looking simple solution uses datatable. saw other code looked simple used events posted @ end, not sure howto form use.
my .aspx page configured as..
<asp:objectdatasource id="gridobjectdatasource" runat="server" selectmethod="bindthrottles" typename="websitenamespace.throttleinterval" sortparametername="sortby"> <selectparameters> <asp:controlparameter controlid="gvthrottles" name="sortdirection" propertyname="sortdirection" /> </selectparameters> </asp:objectdatasource> <asp:gridview id="gvthrottles" allowsorting="true" runat="server" datakeynames="userid" datasourceid="gridobjectdatasource" > <columns> <asp:templatefield headertext="userid" sortexpression="userid"> <itemtemplate> <asp:label id="lblitemuserid" runat="server" text='<%# eval("userid") %>'></asp:label> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="requests" sortexpression="requests"> <itemtemplate> <asp:label id="lblitemnumrequests" runat="server" text='<%# eval("requests") %>'></asp:label> </itemtemplate> </columns> </asp:gridview>
my bindthrottles method configured...
public datatable bindthrottles(string sortby, int sortdirection){ //..code run queries mongodb //..code create columns , rows of datatable //..code fill rows data mongodb ************************************************************* //.. need code here let datatable sort on //.. column header link asc or desc. ************************************************************* }
i saw stackoverflow post shows code like...
dt.defaultview.sort = e.sortexpression + " " + getsortdirection(e.sortexpression);
and getsortdirection configured
public string getsortdirection(string column) { // default, set sort direction ascending. string sortdirection = "asc"; // retrieve last column sorted. string sortexpression = viewstate["sortexpression"] string; if (sortexpression != null) { // check if same column being sorted. // otherwise, default value can returned. if (sortexpression == column) { string lastdirection = viewstate["sortdirection"] string; if ((lastdirection != null) && (lastdirection == "asc")) { sortdirection = "desc"; } } } // save new values in viewstate. viewstate["sortdirection"] = sortdirection; viewstate["sortexpression"] = column; return sortdirection; }
but don't know how form can use events sort inside function has set parameters not events, or if there better way sort both asc , desc column header link.
additional information: new asp. inherited project, why function still called bindthrottles, thought trying eliminate binding(co-workers advice).
here in function sortexpression column name , sortdirection order sort ie(ascending or descending ). both values stored in viewstate can use in event.you can use function :
dataview dv = new dataview(dttable); dv.sort = columnname + " " + getsortdirection(columnname); gridview1.datasource = dv; dttable = dv.totable(); gridview1.databind();
where dttable datatable
Comments
Post a Comment