Page no in datagrid

J

Jazz

hello
I have a datagrid with one coloumns as Hyperlink....

<asp:datagrid Width="100%" id="dgResults" runat="server"
cellpadding="5" onItemCommand="detailsClicked"
OnItemDataBound="checkRated" AutoGenerateColumns="False"
AllowPaging="True" PageSize="25" OnPageIndexChanged="dgResults_Paged">

<asp:ButtonColumn Text="Details" HeaderText="Candidate
Details"></asp:ButtonColumn>
<PagerStyle HorizontalAlign="Center" BackColor="#1B4472"
PageButtonCount="20" Mode="NumericPages"></PagerStyle>
</asp:datagrid>

When i click on this hyperlink ,
it fires another function called detailsClicked()

Sub detailsClicked(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
If e.Item.Cells.Count > 1 Then
Dim user_id As TableCell = e.Item.Cells(0)
Dim id As String = user_id.Text
Dim b_id As TableCell = e.Item.Cells(1)
Dim bid As String = b_id.Text
Response.Redirect("ABC.aspx?admin=true&bid=" & bid & "&id=" &
id) End If
End Sub

My problem starts here... If i do something If i am on page 2 in
datagrid and then click on this hyperlink it takes me to ABC.aspx. Can
i have some link on abc.aspx from where i can go to any page no of my
grid control... e.g if i click on page 2 it should redirect me to the
Page 2 of the grid...
or
if i do somechanges on abc.aspx it should return me back to the
original page in datagrid ....not on the first page...

Thanks
Jazz
 
C

Craig

What I did was to store the current page number in a Session Variable.

Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
Session("CurrentPageNumber") = e.NewPageIndex
sqlDataAdapter1.Fill(MyDataset)
Page.DataBind()
End Sub

When you go to the next page and then come back to the first page set the
page number.

If Not IsPostBack Then
DataGrid1.CurrentPageIndex = Session("CurrentPageNumber")
End If

You could put the current page number on the URL you click on to get to the
second page.
page2.aspx?CurrentPageNumber=2
but then you have to pass it back to the original page.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top