Click here to Skip to main content
15,041,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how sort filed gridview with call function in

please see in sample

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowSorting="True" DataKeyNames="FUserId" OnSorting="GVAS_Sorting"  CssClass="GridViewStyle" DataSourceID="SqlDataSource1" Height="103px" Width="511px" ShowFooter="True" OnRowDataBound="GridView1_RowDataBound">
                          <AlternatingRowStyle CssClass="AltRowStyle" />
                             <asp:TemplateField HeaderText="مجموع حقوق" SortExpression="SumWage">
                                    <asp:Label ID="lSumWage" Font-Underline="false" runat="server"
                                        Text='<%# SumWage() %>' />
                                <ItemStyle HorizontalAlign="Center" />
                    <asp:Label ID="lbSumWage" runat="server" Text="Label"></asp:Label>
<asp:TemplateField HeaderText="نام کاربر">
                                    <asp:Label ID="fullNAME" Font-Underline="false" runat="server"
                                        Text='<%# TempFullName() %>' />
                                <ItemStyle HorizontalAlign="Center" />

                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ICTPortalDBConnectionString %>" SelectCommand="SELECT   FFamily,FName,FUserId From Tuser "></asp:SqlDataSource>

public string SumWage()

       return temp.retpricereq(u2,str).ToString();

how sort with SortExpression="SumWage" sumwage()

1 solution

You can change your mathod to a static method like

public static string SumWage()

        return temp.retpricereq(u2,str).ToString();

Then use like

Text='<%# Class.SumWage() %>' 

// Class is the Class where your SumWage Method resides.

Hope this helps...
saeed1364 3-Oct-13 13:08pm
iam dont sorting
JoCodes 3-Oct-13 13:15pm
any error you are getting? Have you tried replacing the method with a hardcoded string and checked whether it works?
saeed1364 3-Oct-13 13:23pm
this main function

public string SumWage()
string str = string.Empty;
int u2 = int.Parse(Eval("FUserId").ToString());
if (ConstList.CheckFormatDate(Ttimef.Text.Trim()) != 0 && Ttimef.Text.Trim() != "")
str += "and [FReqDate] >= " + ConstList.DateStoM(Ttimef.Text.Trim()).Date.ToShortDateString();

if (ConstList.CheckFormatDate(Ttimet.Text.Trim()) != 0 && Ttimet.Text.Trim() != "")
str += " and FReqDate <= " + ConstList.DateStoM(Ttimet.Text.Trim()).Date.ToShortDateString();

return temp.retpricereq(u2, str).ToString();
//return "1";

dont use static
JoCodes 3-Oct-13 13:36pm
IS your method in your codebhind page?
JoCodes 3-Oct-13 13:31pm
static funtion was to make the function access like '<%# %>'
saeed1364 3-Oct-13 13:35pm
when use static dont know Eval("FUserId").ToString());
saeed1364 3-Oct-13 13:37pm
Error 4 An object reference is required for the non-static field, method, or property 'System.Web.UI.TemplateControl.Eval(string)'
JoCodes 3-Oct-13 13:43pm
Eval wont work since its non statc . check the below comment which includes a link how to use non static methods with Eval
JoCodes 3-Oct-13 13:40pm
Can you check this if you want to use Eval ..

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