473,503 Members | 722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

e.item.cells and paged datagrid

I have a paged datagrid that when built consists of several pages.
On each page there an ID number which is to be sent in a call another
page, like this:

Private Sub dgResults_ItemCommand(ByVal source As System.Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgResults.ItemCommand
If e.CommandName = "ViewID" Then
Response.Redirect("IDdetail.aspx?ID=" &
e.Item.Cells(2).Text.ToString)
End If
End Sub
Problem is that e.items.cells(2)is always taken from the corresponding
position on page 1. Eg Page one might have a list of ids 2,4,6,8 and
page 10 has ids 3,5,7,9. If I view page 10 and click 9 e.item.cells(2)
is equal to 8

Any suggestions on how to pass the correct ID?

Thanks,
Bob

*******************
The other code used

Page_load
Dim oDT as New DataTable
oDT = oDAL.GetAllID(fielda,fieldb, etc) -- call a sql sproc

If oDT.Rows.Count > 0 Then
dgResults.DataSource = oDT.DefaultView
dgResults.DataBind()
lblTotalRecs.Text = "Total Records: " & oDT.Rows.Count.ToString

Private Sub dgResults_PageIndexChanged(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles
dgResults.PageIndexChanged
dgResults.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub

Private Sub BindGrid()
Dim oDV As New DataView
oDV = dgResults.DataSource
dgResults.DataSource = oDV
dgResults.DataBind()
oDV.Dispose()
End Sub

Nov 19 '05 #1
6 1981
Hey,

why dont you store the ID into a Label control and use
e.item.findControl("MyID")? That way, you will always get the correct value.

--
Sonu Kapoor - [MCP]
ASP.NET Moderator
WebSite: http://www.Kapoorsolutions.com
Blog: http://www.Kapoorsolutions.com/blog/
ASP.NET News: http://www.Kapoorsolutions.com/reblogger/

"yer darn tootin" wrote:
I have a paged datagrid that when built consists of several pages.
On each page there an ID number which is to be sent in a call another
page, like this:

Private Sub dgResults_ItemCommand(ByVal source As System.Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgResults.ItemCommand
If e.CommandName = "ViewID" Then
Response.Redirect("IDdetail.aspx?ID=" &
e.Item.Cells(2).Text.ToString)
End If
End Sub
Problem is that e.items.cells(2)is always taken from the corresponding
position on page 1. Eg Page one might have a list of ids 2,4,6,8 and
page 10 has ids 3,5,7,9. If I view page 10 and click 9 e.item.cells(2)
is equal to 8

Any suggestions on how to pass the correct ID?

Thanks,
Bob

*******************
The other code used

Page_load
Dim oDT as New DataTable
oDT = oDAL.GetAllID(fielda,fieldb, etc) -- call a sql sproc

If oDT.Rows.Count > 0 Then
dgResults.DataSource = oDT.DefaultView
dgResults.DataBind()
lblTotalRecs.Text = "Total Records: " & oDT.Rows.Count.ToString

Private Sub dgResults_PageIndexChanged(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles
dgResults.PageIndexChanged
dgResults.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub

Private Sub BindGrid()
Dim oDV As New DataView
oDV = dgResults.DataSource
dgResults.DataSource = oDV
dgResults.DataBind()
oDV.Dispose()
End Sub

Nov 19 '05 #2
You could pass the ID as the CommandArgument in your Button. It would make
the code much more clean and self-contained, rather than digging into the
Cells of the grid.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I have a paged datagrid that when built consists of several pages.
On each page there an ID number which is to be sent in a call another
page, like this:
Private Sub dgResults_ItemCommand(ByVal source As System.Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgResults.ItemCommand
If e.CommandName = "ViewID" Then
Response.Redirect("IDdetail.aspx?ID=" &
e.Item.Cells(2).Text.ToString)
End If
End Sub
Problem is that e.items.cells(2)is always taken from the corresponding
position on page 1. Eg Page one might have a list of ids 2,4,6,8 and
page 10 has ids 3,5,7,9. If I view page 10 and click 9 e.item.cells(2)
is equal to 8

Any suggestions on how to pass the correct ID?

Thanks,
Bob
*******************
The other code used
Page_load
Dim oDT as New DataTable
oDT = oDAL.GetAllID(fielda,fieldb, etc) -- call a sql sproc
If oDT.Rows.Count > 0 Then
dgResults.DataSource = oDT.DefaultView
dgResults.DataBind()
lblTotalRecs.Text = "Total Records: " & oDT.Rows.Count.ToString
Private Sub dgResults_PageIndexChanged(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles
dgResults.PageIndexChanged
dgResults.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
Private Sub BindGrid()
Dim oDV As New DataView
oDV = dgResults.DataSource
dgResults.DataSource = oDV
dgResults.DataBind()
oDV.Dispose()
End Sub


Nov 19 '05 #3
Thanks guys.

Brock, have you got a snippet of code to show me how you'd do this?

The problem is that whatever's wrong, clicking a row's 'View' button on
page 2,3,4 etc always selects the correspondingly positioned ID off the
first page. My problem I can't figure out where the correct ID is being
stored, so I can't pass it to anything.

e.Item.Cells(2) is always an ID from the first page, and despite being
able to view ID's page 2,3,4 etc and click the corresponding view
button I can't get the correct ID passed, to anything, label or
otherwise.

Nov 19 '05 #4

Workaround in place:
Instead of using the ItemCommand thingy I'm now using the ID field as a
HyperLink column in the datagrid,

ie
<asp:HyperLinkColumn Text="The ID " DataNavigateUrlField="ID"
DataNavigateUrlFormatString="IDdetail.aspx?id={0}"
DataTextField="ID" </asp:HyperLinkColumn>

Much simpler. Not sure what my colleague who wrote in the ItemCommand
was thinking, but to be fair I think on a non-paged datagrid it'd work
fine, that's how the page started out.

Nov 19 '05 #5
> Brock, have you got a snippet of code to show me how you'd do this?

In the ASPX ItemTemplate:

<asp:Button runat=server .... CommandName="ViewID" CommandArgument='<%# DataBinder.Eval(Container.DataItem,
"ID")%>'

Then in your code, ItemCommand, the Button's CommandArgument will be the
ID for that row form the DB.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Thanks guys.
The problem is that whatever's wrong, clicking a row's 'View' button
on page 2,3,4 etc always selects the correspondingly positioned ID off
the first page. My problem I can't figure out where the correct ID is
being stored, so I can't pass it to anything.

e.Item.Cells(2) is always an ID from the first page, and despite being
able to view ID's page 2,3,4 etc and click the corresponding view
button I can't get the correct ID passed, to anything, label or
otherwise.


Nov 19 '05 #6

Thanks Brock, that's just the job. I'll give it a go.

Brock Allen wrote:
Brock, have you got a snippet of code to show me how you'd do this?


In the ASPX ItemTemplate:

<asp:Button runat=server .... CommandName="ViewID" CommandArgument='<%# DataBinder.Eval(Container.DataItem,
"ID")%>'

Then in your code, ItemCommand, the Button's CommandArgument will be the
ID for that row form the DB.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7803
by: Stephen | last post by:
I am trying to delete a row in a datagrid on the onclick of a asp:ButtonColumn. The datagrid is created from the items in an arraylist so what im trying to do is remove the item from the array and...
1
1671
by: Yangtsi River | last post by:
Hi, I am retrive record from an Access database and want them displayed page by page, I used oledbdatareader to retrive and assigned the datasource of datagrid control to this reader. but the...
1
2261
by: Hajime Kusakabe | last post by:
I made a datagrid and it contains several columns. The number of columns depend on what users select from a dropdown list. Therefore the number of columns changes. I would like to find the last...
3
4363
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would...
4
2287
by: Chris | last post by:
Using: DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand is there a way to find a specific item in the...
4
1466
by: Kurt Schroeder | last post by:
I have a data grid with about 20 repeating items. they data: colors, red colors,blue colors, green Animals cat animals bird people, Tom people, Bill people, Kris
3
1390
by: louise raisbeck | last post by:
Hi, I have been on this for hours and just cannot work it out. I have a datagrid. I set the edititem index to a row to edit, that works. However if i want to put a value into this textbox it wont...
0
1198
by: B-lv | last post by:
I have an admin script to modify data in an Access db, but when I hit the update button after changing a field, I get a "Specified argument was out of the range of valid values. Parameter name:...
0
1023
by: toddw607 | last post by:
I have a datagrid in ASP.NET using VB.NET code which, when loaded it takes a parameter from the URL called DexNumb. When this parameter is brought it, it highlights the entire row Red and makes it...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.