Solved

datagrid month paging

Posted on 2009-06-30
7
243 Views
Last Modified: 2012-05-07
Yes is there any examples in vb or c# to have a datagrid paging by month.
0
Comment
Question by:sevensnake77
  • 4
  • 3
7 Comments
 
LVL 12

Expert Comment

by:wht1986
ID: 24751282
You could emulate it by setting the filter property on a bindingsource

e.g. I have a form with a datagrid, a dataset, and a bindingsource on it
the bindingsource's data source is the dataset
the data grid's data source is the bindingsource

to page to a certain month (say january this year) you can set the filter to something like
BindingSource1.Filter = "DateColumn >= '1/1/2009' and DateColumn < '2/1/2009'"

then only the one month would be visible in the datagrid
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24751499
Well more like for example
April        May
datagrid###
 
you will click on May and it will take you to june or click on April and take you to march, But I need it to show upMarch or shop up June.
0
 
LVL 12

Expert Comment

by:wht1986
ID: 24759842
That's essentially what I was trying to show you. I created a working sample project for you here http://www.kevinwhite.net/sevensnake.zip
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 9

Author Comment

by:sevensnake77
ID: 24763182
Understood but this is is a windows form. do you have an asp.net vb.net example for a web display
0
 
LVL 12

Accepted Solution

by:
wht1986 earned 500 total points
ID: 24764244
Attached
================

Default.aspx

================
 

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

    <body>

        <form id="form1" runat="server">

        <asp:GridView ID="GridView1" runat="server"></asp:GridView>

        <table>

            <tr>

                <td>

                    <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="YearSelected" AutoPostBack="true">

                        <asp:ListItem Text="2009" />

                        <asp:ListItem Text="2008" />

                    </asp:DropDownList>

                </td>

                <td><asp:LinkButton ID="LinkButton01" runat="server" Text="Jan" OnClick="MonthSelected" /></td>

                <td><asp:LinkButton ID="LinkButton02" runat="server" Text="Feb" OnClick="MonthSelected" /></td>

                <td><asp:LinkButton ID="LinkButton03" runat="server" Text="Mar" OnClick="MonthSelected" /></td>

                <td><asp:LinkButton ID="LinkButton04" runat="server" Text="Apr" OnClick="MonthSelected" /></td>

                <td><asp:LinkButton ID="LinkButton05" runat="server" Text="May" OnClick="MonthSelected" /></td>

                <td><asp:LinkButton ID="LinkButton06" runat="server" Text="Jun" OnClick="MonthSelected" /></td>

                <td><asp:LinkButton ID="LinkButton07" runat="server" Text="Jul" OnClick="MonthSelected" /></td>

                <td><asp:LinkButton ID="LinkButton08" runat="server" Text="Aug" OnClick="MonthSelected" /></td>

                <td><asp:LinkButton ID="LinkButton09" runat="server" Text="Sep" OnClick="MonthSelected" /></td>

                <td><asp:LinkButton ID="LinkButton10" runat="server" Text="Oct" OnClick="MonthSelected" /></td>

                <td><asp:LinkButton ID="LinkButton11" runat="server" Text="Nov" OnClick="MonthSelected" /></td>

                <td><asp:LinkButton ID="LinkButton12" runat="server" Text="Dec" OnClick="MonthSelected" /></td>

            </tr>

        </table>

        </form>

    </body>

</html>
 

================

Default.aspx.vb

================
 

Imports System.Data
 

Partial Class _Default

    Inherits System.Web.UI.Page
 

    Dim months As String() = {"", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
 

    'create a data table and mock data for the example

    Private Function CreateMockData() As DataTable

        Dim d As DataTable = New DataTable()

        d.Columns.Add("MyDateColumn", Type.GetType("System.DateTime"))

        d.Columns.Add("MyStringColumn1", Type.GetType("System.String"))

        d.Columns.Add("MyStringSolumn2", Type.GetType("System.String"))

        d.Rows.Add(New Object() {New DateTime(2008, 1, 2), "Bob", "Barker"})

        d.Rows.Add(New Object() {New DateTime(2009, 1, 2), "Bob", "Marley"})

        d.Rows.Add(New Object() {New DateTime(2008, 10, 8), "Bob", "Villa"})

        d.Rows.Add(New Object() {New DateTime(2009, 4, 12), "Bob", "InTheWater"})

        d.Rows.Add(New Object() {New DateTime(2009, 4, 28), "Bob", "Ber"})

        Return d

    End Function
 

    ' store in viewstate since we dont have a valid sql datasource

    Public Property Data() As DataTable

        Get

            If IsNothing(ViewState("DATATABLE")) Then

                Me.Data = CreateMockData()

            End If

            Return ViewState("DATATABLE")

        End Get

        Set(ByVal value As DataTable)

            ViewState("DATATABLE") = value

        End Set

    End Property
 

    Public Property SelectedYear() As Integer

        Get

            If IsNothing(ViewState("SelectedYear")) Then

                Me.SelectedYear = 2008

            End If

            Return ViewState("SelectedYear")

        End Get

        Set(ByVal value As Integer)

            ViewState("SelectedYear") = value

        End Set

    End Property
 

    Public Property SelectedMonth() As Integer

        Get

            If IsNothing(ViewState("SelectedMonth")) Then

                Me.SelectedMonth = 1

            End If

            Return ViewState("SelectedMonth")

        End Get

        Set(ByVal value As Integer)

            ViewState("SelectedMonth") = value

        End Set

    End Property
 

    Protected Sub MonthSelected(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim lb As LinkButton = sender

        SelectedMonth = Array.IndexOf(months, lb.Text)

        SetFilter()

    End Sub
 

    Protected Sub YearSelected(ByVal sender As Object, ByVal e As System.EventArgs)

        SelectedYear = Integer.Parse(DropDownList1.SelectedItem.Text)

        SetFilter()

    End Sub
 

    Private Sub SetFilter()

        Dim startDate As DateTime = New DateTime(SelectedYear, SelectedMonth, 1)

        Dim endDate As DateTime = startDate.AddMonths(1)

        Dim filter As String = String.Format("MyDateColumn >= '{0}' and MyDateColumn < '{1}'", startDate.ToShortDateString(), endDate.ToShortDateString())
 

        GridView1.EmptyDataText = String.Format("No records for {0} {1}", months(Me.SelectedMonth), Me.SelectedYear)
 

        Dim dv As DataView = New DataView(Me.Data)

        dv.RowFilter = filter

        GridView1.DataSource = dv

        GridView1.DataBind()

    End Sub
 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

            SetFilter()

        End If

    End Sub
 
 

End Class

Open in new window

0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 31598520
Thanks
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24818203
wht>> I figured you aremore familar with this maybe you can help with this one.

http://www.experts-exchange.com/Programming/Languages/.NET/Q_24557798.html
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Linq Help 1 35
vb.net checkbox 7 41
Host asp.net pages 5 25
Error "String or binary data would be truncated" in an update on a datatable 7 28
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now