Gridview - Paging - Linkbutton - Problem

R

Ram

Hi All,

I am binding a GridView control using object data source. I have
included a linkbutton with in the gridview and using its commandname
property , I am passing few values( id and name fields). I have set the
AllowPaging property to true and Pagesize property to 5.

While running the application, in the first page of the gridview
things are working fine. ie. On licking the linkbutton values are
passed correctly to the target page . But in the second page , values
are not passed correctly. It takes the values of the corresponding row
from the first page of the grid view and hence wrong values are passed
to the target page.

Please help me in solving this problem.

Thanks in advance.


Regards,
S.Ramalingam.
 
E

Erik Funkenbusch

Please help me in solving this problem.

Without seeing your source code, my only guess is that you're using the
wring property to index into your recordset.
 
R

Ram

Erik said:
Without seeing your source code, my only guess is that you're using the
wring property to index into your recordset.

Hi Erik,

Thanks for replying. Here is the source code.

sample.aspx
------------------
<asp:GridView id="GV_bookings" DataSourceID="Obj_bookings"
runat="server" allowpaging="True" PageSize="5"
autogeneratecolumns="False" >
<Columns>
<asp:TemplateField HeaderText="Booking Number" >
<ItemTemplate>
<asp:LinkButton ID="lbBookingNo"
runat="server" OnClick="LinkButton_OnClick"
CommandName='<%#
"bookingDetails.aspx?bookingId=" + Eval("bookingId")%>' Text='<%#
Eval("bookingNo") %>'>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>

<asp:BoundField DataField="employeeName"
HeaderText="Employee Name" />
<asp:BoundField DataField="consultantName"
HeaderText="Consultant Name" />
</Columns>
</asp:gridview>

<asp:ObjectDataSource ID="Obj_bookings" runat="server"
SelectMethod="getAllBookings"
TypeName="Bookings"></asp:ObjectDataSource>

sample.aspx.cs
----------------------

protected void LinkButton_OnClick(object sender, EventArgs args)
{
LinkButton lb = (LinkButton)sender;
Server.Transfer(lb.CommandName);
}

I hope u understand this simple code. I haven't written anything more
than this. On clicking the booking number (link button) in the grid
view , the id and bookingno are passed to the "bookingDetails.aspx"
page. This is working fine for the first five records( ie for the first
page of the gridview). But in the second page if I click the link
button , say in the first row , the values in the first row of the
first page is passed to the next page.ie the actual values are not
passed.

Pls revert back with some good suggestions.


Regards,
S.Ramalingam
 
E

Erik Funkenbusch

I hope u understand this simple code. I haven't written anything more
than this. On clicking the booking number (link button) in the grid
view , the id and bookingno are passed to the "bookingDetails.aspx"
page. This is working fine for the first five records( ie for the first
page of the gridview). But in the second page if I click the link
button , say in the first row , the values in the first row of the
first page is passed to the next page.ie the actual values are not
passed.

Honestly, I'm not even sure why your code is working at all.

You should be doing this:

<asp:LinkButton ...
CommandName='bookingDetails.aspx?bookingId=<%#Eval("bookingNo") %>' ... />

This probably isn't the right thing to do, though. You should probably use
the HyperLinkField instead, this allows you to more easily bind the value
as well as the text. Set the DataNavigateField to bookingNo, and the
DataNavigateUrlFormatString to "bookingDetails.aspx?bookingId={0}"
 
R

Ram

Hi Erik,

Thanks again for u'r suggestion. In case of hyperlink fields the
values are displayed in the address bar. That's why I used link
buttons. But the thing is , the code works well when I am using it in
separate pages . But it doesn't seem to work when I am using nested
master pages.The "LinkButton_onClick" event is wriitten in a separate
class file since in many screens of my application I am using the
gridview with link buttons.


Thanks and Regards,
S.Ramalingam
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top