Datetime formating and paging

G

Guest

Hi
I'm trying to create a pager that allows you to show records by year and
month! I am getting close but would really appritiate some help!

Can someone please tell me how I convert the value of (i) into a date so that

l.Text shows the date as Feb or Mar etc etc

EG:
If i = 1
then I want it to equal "Jan"
or
If i = 2
then I want it to equal "Feb"

Likewise

l.commandArgument should equal a date that can be cross referenced from a
datetime column in a database!

I would really appritiate any help! Thanks...


<code>

Private Sub DGAnno_ItemCreated(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles DGAnno.ItemCreated
If e.Item.ItemType = ListItemType.Footer Then
e.Item.Cells.Clear()

Dim tc As New TableCell
tc.ColumnSpan = 3
e.Item.Cells.Add(tc)
Dim spacer As New LiteralControl
spacer.Text = " "
tc.Controls.Add(spacer)
'Adds year list to the footer of the DataGrid
Dim rightNow As DateTime = DateTime.Now
Dim s As Integer 'create a string
s = rightNow.ToString("yyyy")
Dim i As Integer
For i = 1 To Right(s, Len(s) - InStr(s, "0"))
Dim l As New LinkButton
Dim lc As New LiteralControl
lc.Text = " "
l.Text = "200" & (i)
l.CommandName = "iDate"
l.CommandArgument = "200" & (i)
tc.Controls.Add(l)
tc.Controls.Add(lc)
Next

e.Item.Cells.Add(tc)
spacer.Text = "&nbsp; "
tc.Controls.Add(spacer)
Dim lb As New LiteralControl
lb.Text = "<br>"
tc.Controls.Add(lb)
'Adds month list to the footer of the DataGrid
Dim month As DateTime = DateTime.Now
Dim m As Integer 'create a string
m = month.ToString("MM")
For i = 1 To m
Dim l As New LinkButton
Dim lc As New LiteralControl
lc.Text = " "
l.Text = (i)
l.CommandName = "imonth"
l.CommandArgument = (i)
tc.Controls.Add(l)
tc.Controls.Add(lc)
Next
End If
End Sub
 
B

Bruce Barker

Look at the data structure called an Array. you create a 12 element string
array with the month number as an index, and the value the month's name.

-- bruce (sqlwork.com)
 
K

Katy King

From: "Bruce Barker" <[email protected]>
| Look at the data structure called an Array. you create a 12 element
string
| array with the month number as an index, and the value the month's name.

There already exists one of these:
DateTimeFomatInfo.InvariantInfo.AbbreviatedMonthNames has an array
containing "Jan", "Feb", etc. You may have to adjust for a zero-based vs.
one-based array.

Katy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top