Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need some clarification regarding the Page Views count of a site. I have a ASP.Net MVC application and there is a GridView in a page which has paging enabled and contains 10 pages.

So, whenever the user navigates to different pages of the GridView the Page Views count will get increased or it will get increased only when the user navigates to some other page?

Also, the Page Views count will get increased when we download images, pdf, word or any other documents from the site?

Please explain clearly.

Thanks in advance
Posted

1 solution

here is an example through which you can show grid with paging..
Below code is for aspx page:
XML
<asp:DataGrid ID="dgadvetise" runat="server" AutoGenerateColumns="False"


                        onpageindexchanged="dgadvetise_PageIndexChanged"

                        PageSize="5" AllowPaging="True" AllowSorting="True" DataKeyField="ID">
                        <PagerStyle HorizontalAlign="Center" Mode="NumericPages"
                         Position="TopAndBottom"/>

                    <Columns>
                            <asp:BoundColumn DataField="ID" HeaderText="Image ID" Visible="False" />
                            <asp:BoundColumn DataField="Name" HeaderText="Name" />
                            <asp:BoundColumn DataField="Link" HeaderText="Link" />
                            <asp:TemplateColumn HeaderText="Image">
                                <ItemTemplate>
                                    <ul class="hoverbox">
                                        <li>
                                            <a href="#"><img id="imgSmall" src='Picture/<%# DataBinder.Eval(Container, "DataItem.ImagePath") %>' alt="Gallery Image" width="100" height="100" /></a>
                                        </li>
                                    </ul>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:FileUpload ID="flUploadGrid" runat="server" ForeColor="#2A2F0F"></asp:FileUpload>
                                </EditItemTemplate>
                                <HeaderStyle Width="110px" />
                            </asp:TemplateColumn>
                            <asp:EditCommandColumn CancelText="Cancel" EditText="Edit" HeaderText="Modify" UpdateText="Update"/>
                            <asp:ButtonColumn CommandName="Delete" Text="Delete" HeaderText="Remove"/>
                        </Columns>
                    </asp:DataGrid>
                    <asp:SqlDataSource ID="nayumaadminconnectionstring" runat="server"
                        ConnectionString="<%$ ConnectionStrings:nayumaConnectionString %>"
                        SelectCommand="SELECT * FROM [Details]"></asp:SqlDataSource>

And the cs page code is:
C#
protected void dgadvetise_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
        dgadvetise.CurrentPageIndex = e.NewPageIndex;

        BindGrid();
    }
protected void BindGrid()
    {
        cls.PopulateGrid(dgadvetise, "Select ID, Name, Link, ImagePath from Details order by ID", this.Page);
    }

I am using a common class which is mentioned below:
C#
public void PopulateGrid(GridView grdView, string sqlQuery, Page form)
    {
        try
        {
            adp = new SqlDataAdapter(sqlQuery, conn);
            tbl = new DataTable();
            adp.Fill(tbl);
            grdView.DataSource = tbl;
            grdView.DataBind();
        }
        catch (Exception ex)
        {
            MsgBox("Populate GridView Error: " + ex.Message, form);
        }
    }

NB: specify your connection in the class file.

I hope this above code will help you.
 
Share this answer
 
Comments
ragasai 16-Nov-11 23:08pm    
@Biswarup88,

I think you are not clear about my question and I am really sorry about the confusion. I am asking about the Google Analytics kind of Page Views count feature and not paging feature in GridView.

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