Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > ItemCommand, ButtonColumn and Paging

Thread Tools

ItemCommand, ButtonColumn and Paging
Posts: n/a
Hi all,

I hope you can help me out on this one. I am creating a dynamic
datagrid within a user control. I have a function that builds columns
and formats the datagrid in Page_Init. I add the datagrid to a table
control dynamically in Page_Load.

When I build the columns, I set the first column in the control to be a
buttoncolumn as follows:

btc = New ButtonColumn()
btc.ButtonType = ButtonColumnType.PushButton
btc.Text = "Details"
btc.CommandName = "Details"

After all columns are designed, I call a function that sets paging
dg1.PagerStyle.Mode = PagerMode.NextPrev
dg1.PagerStyle.NextPageText = "Next >"
dg1.PagerStyle.PrevPageText = "< Previous"

The problem occurs when ItemCommand is fired during paging. It works
fine for "Next", but "Previous" is causing a problem -- the
e.CommandName returns "Details", which is the command name for the
button column.

Public Sub dg1_ItemCommand(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs) Handles dg1.ItemCommand

If e.CommandName <> "Page" Then
Dim tcButtonCol As TableCell = e.Item.Cells(0)
Dim tcDayCode As TableCell = e.Item.Cells(1)
DayCode = Trim(tcDayCode.Text)

RaiseEvent DGButtonClick(sender, e)
End If

End Sub

Does anyone why this is happening and how to resolve it? I have tried
e.Item.ItemIndex = -1, but "Previous" returns index 9 (and my grid
PageSize is 10). I've also tried e.CommandArgument, which returns
"Next" for Next, but empty string for Previous.

Thanks for your help,

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ButtonColumn and EditCommandColumn don't work together as expected in DataGrid Piotr ASP .Net 0 01-06-2006 02:21 PM
Combining numeric mode paging and nextPreview paging in datagrid Red ASP .Net 1 03-12-2005 11:41 PM
datagrid paging - customising paging style wh1974 ASP .Net 0 01-12-2005 03:48 PM
DataSet paging vs Datareader paging =?Utf-8?B?UGF0cmljay5PLklnZQ==?= ASP .Net 1 10-08-2004 02:13 PM
Paging Dr. Who, Paging Dr. Who... Computer Security 1 07-02-2004 08:59 PM