Click here to Skip to main content
15,907,225 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Milliseconds from excel Pin
kjell.ek16-May-22 23:15
kjell.ek16-May-22 23:15 
AnswerRe: Milliseconds from excel Pin
Raj Kumar7918-Oct-22 5:12
Raj Kumar7918-Oct-22 5:12 
QuestionASP.NET Gridview load data Pin
Herman<T>.Instance28-Apr-22 3:16
Herman<T>.Instance28-Apr-22 3:16 
AnswerRe: ASP.NET Gridview load data Pin
Richard Deeming28-Apr-22 4:40
mveRichard Deeming28-Apr-22 4:40 
GeneralRe: ASP.NET Gridview load data Pin
Herman<T>.Instance2-May-22 0:47
Herman<T>.Instance2-May-22 0:47 
GeneralRe: ASP.NET Gridview load data PinPopular
Dave Kreskowiak2-May-22 2:12
mveDave Kreskowiak2-May-22 2:12 
GeneralRe: ASP.NET Gridview load data Pin
Herman<T>.Instance2-May-22 3:23
Herman<T>.Instance2-May-22 3:23 
GeneralRe: ASP.NET Gridview load data Pin
Herman<T>.Instance3-May-22 4:46
Herman<T>.Instance3-May-22 4:46 
And now in CODE
(used the ScottGu mentioned code in the link from first reply)
Created a clean asp.net 4.7.2 webforms project.
I have an ODATA service which is read via Unchase OData library
Index.Asp has the gridview:
ASP.NET
<asp:GridView runat="server" ID="GrdTest"
                AutoGenerateColumns="false" DataKeyNames="Id"
                ItemType="MarinGlobalService.Models.User"
                SelectMethod="GrdTest_GetData"
                >
                <Columns>
                    <asp:DynamicField DataField="Name" HeaderText="Name" />
                    <asp:DynamicField DataField="SurName" HeaderText="Surname"  />
                    <asp:DynamicField DataField="GivenName" HeaderText="GivenName"  />
                    <asp:TemplateField HeaderText="# of Usergroups">
                        <ItemTemplate><%# Item.UserGroup.Count %></ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
My codebehind:
C#
namespace TestGridView
{
    public partial class Index : Page
    {

        private Default.Container container; // is for working with the OData Service

        protected void Page_Init(object sender, EventArgs e)
        {
            Uri uri = new Uri("<a href="http://localhost/api/global">http://localhost/api/global</a>");
            container = new Default.Container(uri)
            {
                Credentials = CredentialCache.DefaultNetworkCredentials,
                Timeout=3600
            };
        }
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            GrdTest.BackColor = System.Drawing.Color.LightGreen;
            GrdTest.AlternatingRowStyle.BackColor = System.Drawing.Color.LightBlue;
            GrdTest.RowStyle.BackColor = System.Drawing.Color.LightGray;
        }

        // The return type can be changed to IEnumerable, however to support
        // paging and sorting, the following parameters must be added:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable<User> GrdTest_GetData(int? maximumRows, int? startRowIndex)
        {
            if (maximumRows == null || startRowIndex == null)
                return container.Users;

            return container.Users.Skip(startRowIndex ?? 0).Take(maximumRows ?? 0);
        }
    }
}
This will lead to 1 gridview without paging and shows data.

Then I change my GridView to:
ASP.NET
<asp:GridView runat="server" ID="GrdTest"
                AutoGenerateColumns="false" DataKeyNames="Id"
                ItemType="MarinGlobalService.Models.User"
                SelectMethod="GrdTest_GetData"
                AllowPaging="true" PageSize="5"
                >
                <Columns>
                    <asp:DynamicField DataField="Name" HeaderText="Name" />
                    <asp:DynamicField DataField="SurName" HeaderText="Surname"  />
                    <asp:DynamicField DataField="GivenName" HeaderText="GivenName"  />
                    <asp:TemplateField HeaderText="# of Usergroups">
                        <ItemTemplate><%# Item.UserGroup.Count %></ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
And the answer is:
C#
[ArgumentException: must be reducible node]
   System.Linq.Expressions.Expression.VisitChildren(ExpressionVisitor visitor) +97
   System.Linq.Expressions.ExpressionVisitor.VisitExtension(Expression node) +11
   System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor) +12
   System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) +20
   System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes) +60
   System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) +43
   System.Web.Util.OrderingMethodFinder.VisitMethodCall(MethodCallExpression node) +43
   System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) +12
   System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) +20
   System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes) +60
   System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) +43
   System.Web.Util.OrderingMethodFinder.VisitMethodCall(MethodCallExpression node) +43
   System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) +12
   System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) +20
   System.Web.Util.OrderingMethodFinder.OrderMethodExists(Expression expression) +38
   System.Web.UI.WebControls.QueryableHelpers.IsOrderingMethodFound(IQueryable`1 queryable) +16

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +168
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +105
   System.Web.UI.WebControls.ModelDataSourceView.ProcessSelectMethodResult(DataSourceSelectArguments arguments, DataSourceSelectResultProcessingOptions selectResultProcessingOptions, ModelDataMethodResult result) +393
   System.Web.UI.WebControls.ModelDataSourceView.GetSelectMethodResult(DataSourceSelectArguments arguments) +86
   System.Web.UI.WebControls.ModelDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +14
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
   System.Web.UI.WebControls.ModelDataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +81
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +169
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +71
   System.Web.UI.WebControls.GridView.DataBind() +5
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +93
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +72
   System.Web.UI.Control.EnsureChildControls() +116
   System.Web.UI.Control.PreRenderRecursiveInternal() +49
   System.Web.UI.Control.PreRenderRecursiveInternal() +236
   System.Web.UI.Control.PreRenderRecursiveInternal() +236
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4719

So why does Scott Guthrie gets paging and doesn't it work for me? And what is this reducible node?

Changing the GrdTest_Getdata method to:
C#
public IQueryable<User> GrdTest_GetData(int? maximumRows, int? startRowIndex, out int? totalRowCount, string sortByExpression)
        {
            // if (maximumRows == null || startRowIndex == null)
            var users = container.Users;
            totalRowCount = users.Count();
            return users;

<pre>
        //return container.Users.Skip(startRowIndex ?? 0).Take(maximumRows ?? 0).AsQueryable();
    }</pre>

will allow to have sortByExpression is set, but the collection does not get ordered by it.So AllowSorting will not give issues, only AllowPaging does.
In Word you can only store 2 bytes. That is why I use Writer.


modified 3-May-22 11:22am.

GeneralRe: ASP.NET Gridview load data Pin
Richard Deeming3-May-22 5:31
mveRichard Deeming3-May-22 5:31 
GeneralRe: ASP.NET Gridview load data Pin
Herman<T>.Instance3-May-22 5:38
Herman<T>.Instance3-May-22 5:38 
GeneralRe: ASP.NET Gridview load data Pin
Richard Deeming3-May-22 5:48
mveRichard Deeming3-May-22 5:48 
GeneralRe: ASP.NET Gridview load data Pin
Herman<T>.Instance3-May-22 7:12
Herman<T>.Instance3-May-22 7:12 
GeneralRe: ASP.NET Gridview load data Pin
Richard Deeming3-May-22 21:38
mveRichard Deeming3-May-22 21:38 
GeneralRe: ASP.NET Gridview load data Pin
Herman<T>.Instance3-May-22 22:03
Herman<T>.Instance3-May-22 22:03 
QuestionSend Email using Classic ASP Pin
Ram Teckchandani11-Apr-22 17:28
Ram Teckchandani11-Apr-22 17:28 
AnswerRe: Send Email using Classic ASP Pin
Richard MacCutchan11-Apr-22 22:00
mveRichard MacCutchan11-Apr-22 22:00 
QuestionMVC 5 Prevent Users From Going Back After Logging In or Out Using Identity Framework Pin
Steven Petersen3-Apr-22 9:11
Steven Petersen3-Apr-22 9:11 
AnswerRe: MVC 5 Prevent Users From Going Back After Logging In or Out Using Identity Framework Pin
Richard Deeming3-Apr-22 21:24
mveRichard Deeming3-Apr-22 21:24 
QuestionA question about CreatedAtAction() method Pin
Alex Dunlop23-Mar-22 21:44
Alex Dunlop23-Mar-22 21:44 
AnswerRe: A question about CreatedAtAction() method Pin
Richard MacCutchan23-Mar-22 21:50
mveRichard MacCutchan23-Mar-22 21:50 
QuestionA question about routing attribute Pin
Alex Dunlop23-Mar-22 21:41
Alex Dunlop23-Mar-22 21:41 
AnswerRe: A question about routing attribute Pin
Richard MacCutchan23-Mar-22 21:51
mveRichard MacCutchan23-Mar-22 21:51 
GeneralRe: A question about routing attribute Pin
Leeladhar Ladia25-Mar-22 3:46
Leeladhar Ladia25-Mar-22 3:46 
Questionexportar datos de sql server a archivo .csv con C# asp.net Pin
Member 1556240011-Mar-22 8:08
Member 1556240011-Mar-22 8:08 
QuestionPower BI Embedded : Cant doCross Filtering selecting multiple rows on a table visual pressing CTRL Pin
Member 155547063-Mar-22 17:21
Member 155547063-Mar-22 17:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.