gridview: "Viewing record x of y"

G

Guest

I have a girdview with paging enabled. How can I add a message in the footer
to say "Viewing records 1-15 of 45" etc

Thanks
 
G

Guest

I would have a method subscribing to the Selected event of the datasource
object to save total record retrieved in a private variable, e.g.

void DataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs
e)
{
iTotalRecords = ((DataView)e.ReturnValue).Count;
}

Then I would subscribe to the rowCreated event to compose a message from the
pageIndex, pageSize and the total records count, e.g.

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
Label lbl= new Label();
//compse the label text
lbl.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " + ((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//notice that the pager template renders one cell in which
//there is an HTMLTable
e.Row.Cells[0].Controls.Add(lbl);
}
}

I haven't run this code, you might have to debug any typos in it, but it
should give you the idea.
 
G

Guest

Thanks Philip,

I will try this out.
N

Phillip Williams said:
I would have a method subscribing to the Selected event of the datasource
object to save total record retrieved in a private variable, e.g.

void DataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs
e)
{
iTotalRecords = ((DataView)e.ReturnValue).Count;
}

Then I would subscribe to the rowCreated event to compose a message from the
pageIndex, pageSize and the total records count, e.g.

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
Label lbl= new Label();
//compse the label text
lbl.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " + ((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//notice that the pager template renders one cell in which
//there is an HTMLTable
e.Row.Cells[0].Controls.Add(lbl);
}
}

I haven't run this code, you might have to debug any typos in it, but it
should give you the idea.


--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


NH said:
I have a girdview with paging enabled. How can I add a message in the footer
to say "Viewing records 1-15 of 45" etc

Thanks
 
G

Guest

I got it working nicely, thanks. I decided to show a message of "Viewing page
1 of 2" etc.

Is there a way of controlling where the label control is placed in the pager
template? It defaults to positioning itself under some other images I have
already added to the pager setting for navigating between pages. If I wanted
to add the label control to the far right hand side of the pager template, is
there a way to do that?

NH said:
Thanks Philip,

I will try this out.
N

Phillip Williams said:
I would have a method subscribing to the Selected event of the datasource
object to save total record retrieved in a private variable, e.g.

void DataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs
e)
{
iTotalRecords = ((DataView)e.ReturnValue).Count;
}

Then I would subscribe to the rowCreated event to compose a message from the
pageIndex, pageSize and the total records count, e.g.

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
Label lbl= new Label();
//compse the label text
lbl.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " + ((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//notice that the pager template renders one cell in which
//there is an HTMLTable
e.Row.Cells[0].Controls.Add(lbl);
}
}

I haven't run this code, you might have to debug any typos in it, but it
should give you the idea.


--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


NH said:
I have a girdview with paging enabled. How can I add a message in the footer
to say "Viewing records 1-15 of 45" etc

Thanks
 
G

Guest

Thanks Philip, great insight.
Regards
N

Phillip Williams said:
The pager template renders a cell spanning the columns of the GridView. You
can change that columnspan to add a new tablecell on the same row where you
insert your new control. For example:

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
TableCell td = new TableCell();
//compse the tablecell's text
td.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " +
((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//decrease the colspan of the pager cell by 1 to add the new
tablecell
e.Row.Cells[0].ColumnSpan --;
//add the newly created cell to the same row as the pager
e.Row.Cells.Add(td);
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


NH said:
I got it working nicely, thanks. I decided to show a message of "Viewing page
1 of 2" etc.

Is there a way of controlling where the label control is placed in the pager
template? It defaults to positioning itself under some other images I have
already added to the pager setting for navigating between pages. If I wanted
to add the label control to the far right hand side of the pager template, is
there a way to do that?

NH said:
Thanks Philip,

I will try this out.
N

:

I would have a method subscribing to the Selected event of the datasource
object to save total record retrieved in a private variable, e.g.

void DataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs
e)
{
iTotalRecords = ((DataView)e.ReturnValue).Count;
}

Then I would subscribe to the rowCreated event to compose a message from the
pageIndex, pageSize and the total records count, e.g.

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
Label lbl= new Label();
//compse the label text
lbl.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " + ((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//notice that the pager template renders one cell in which
//there is an HTMLTable
e.Row.Cells[0].Controls.Add(lbl);
}
}

I haven't run this code, you might have to debug any typos in it, but it
should give you the idea.


--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

I have a girdview with paging enabled. How can I add a message in the footer
to say "Viewing records 1-15 of 45" etc

Thanks
 
G

Guest

The pager template renders a cell spanning the columns of the GridView. You
can change that columnspan to add a new tablecell on the same row where you
insert your new control. For example:

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
TableCell td = new TableCell();
//compse the tablecell's text
td.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " +
((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//decrease the colspan of the pager cell by 1 to add the new
tablecell
e.Row.Cells[0].ColumnSpan --;
//add the newly created cell to the same row as the pager
e.Row.Cells.Add(td);
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


NH said:
I got it working nicely, thanks. I decided to show a message of "Viewing page
1 of 2" etc.

Is there a way of controlling where the label control is placed in the pager
template? It defaults to positioning itself under some other images I have
already added to the pager setting for navigating between pages. If I wanted
to add the label control to the far right hand side of the pager template, is
there a way to do that?

NH said:
Thanks Philip,

I will try this out.
N

Phillip Williams said:
I would have a method subscribing to the Selected event of the datasource
object to save total record retrieved in a private variable, e.g.

void DataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs
e)
{
iTotalRecords = ((DataView)e.ReturnValue).Count;
}

Then I would subscribe to the rowCreated event to compose a message from the
pageIndex, pageSize and the total records count, e.g.

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
Label lbl= new Label();
//compse the label text
lbl.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " + ((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//notice that the pager template renders one cell in which
//there is an HTMLTable
e.Row.Cells[0].Controls.Add(lbl);
}
}

I haven't run this code, you might have to debug any typos in it, but it
should give you the idea.


--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

I have a girdview with paging enabled. How can I add a message in the footer
to say "Viewing records 1-15 of 45" etc

Thanks
 
G

Guest

Hi again,

I am having a bit of trouble getting this to work. I have the following code
in the grdiview rowcreated event...

If (e.Row.RowType = DataControlRowType.Pager) Then

Dim lbl = New Label()

lbl.Text = "Viewing page " & dgStaff.PageIndex + 1 & " of " &
dgStaff.PageCount
'notice that the pager template renders one cell in which
'there is an HTMLTable

Dim td As TableCell = New TableCell()

e.Row.Cells(0).ColumnSpan = e.Row.Cells(0).ColumnSpan -1
e.Row.Cells(0).Controls.Add(lbl)
'add the newly created cell to the same row as the pager

e.Row.Cells.Add(td)
e.Row.Cells(1).Text = "TEST"

End If

But the new cell is added outside of the width of the gridview, it is a
single new cell on the outside of the right side of the gridview.

I've been playing around with this trying to get it to work but with no
luck, any ideas?
thanks

Phillip Williams said:
The pager template renders a cell spanning the columns of the GridView. You
can change that columnspan to add a new tablecell on the same row where you
insert your new control. For example:

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
TableCell td = new TableCell();
//compse the tablecell's text
td.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " +
((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//decrease the colspan of the pager cell by 1 to add the new
tablecell
e.Row.Cells[0].ColumnSpan --;
//add the newly created cell to the same row as the pager
e.Row.Cells.Add(td);
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


NH said:
I got it working nicely, thanks. I decided to show a message of "Viewing page
1 of 2" etc.

Is there a way of controlling where the label control is placed in the pager
template? It defaults to positioning itself under some other images I have
already added to the pager setting for navigating between pages. If I wanted
to add the label control to the far right hand side of the pager template, is
there a way to do that?

NH said:
Thanks Philip,

I will try this out.
N

:

I would have a method subscribing to the Selected event of the datasource
object to save total record retrieved in a private variable, e.g.

void DataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs
e)
{
iTotalRecords = ((DataView)e.ReturnValue).Count;
}

Then I would subscribe to the rowCreated event to compose a message from the
pageIndex, pageSize and the total records count, e.g.

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
Label lbl= new Label();
//compse the label text
lbl.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " + ((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//notice that the pager template renders one cell in which
//there is an HTMLTable
e.Row.Cells[0].Controls.Add(lbl);
}
}

I haven't run this code, you might have to debug any typos in it, but it
should give you the idea.


--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

I have a girdview with paging enabled. How can I add a message in the footer
to say "Viewing records 1-15 of 45" etc

Thanks
 
G

Guest

Compare your code to the code attached to this demo (at the bottom of the
demo there are 2 tabs; one for code in VB and another for the same code in C#
http://www.webswapp.com/codesamples/aspnet20/gridview_multiplerows_selection/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


NH said:
Hi again,

I am having a bit of trouble getting this to work. I have the following code
in the grdiview rowcreated event...

If (e.Row.RowType = DataControlRowType.Pager) Then

Dim lbl = New Label()

lbl.Text = "Viewing page " & dgStaff.PageIndex + 1 & " of " &
dgStaff.PageCount
'notice that the pager template renders one cell in which
'there is an HTMLTable

Dim td As TableCell = New TableCell()

e.Row.Cells(0).ColumnSpan = e.Row.Cells(0).ColumnSpan -1
e.Row.Cells(0).Controls.Add(lbl)
'add the newly created cell to the same row as the pager

e.Row.Cells.Add(td)
e.Row.Cells(1).Text = "TEST"

End If

But the new cell is added outside of the width of the gridview, it is a
single new cell on the outside of the right side of the gridview.

I've been playing around with this trying to get it to work but with no
luck, any ideas?
thanks

Phillip Williams said:
The pager template renders a cell spanning the columns of the GridView. You
can change that columnspan to add a new tablecell on the same row where you
insert your new control. For example:

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
TableCell td = new TableCell();
//compse the tablecell's text
td.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " +
((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//decrease the colspan of the pager cell by 1 to add the new
tablecell
e.Row.Cells[0].ColumnSpan --;
//add the newly created cell to the same row as the pager
e.Row.Cells.Add(td);
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


NH said:
I got it working nicely, thanks. I decided to show a message of "Viewing page
1 of 2" etc.

Is there a way of controlling where the label control is placed in the pager
template? It defaults to positioning itself under some other images I have
already added to the pager setting for navigating between pages. If I wanted
to add the label control to the far right hand side of the pager template, is
there a way to do that?

:

Thanks Philip,

I will try this out.
N

:

I would have a method subscribing to the Selected event of the datasource
object to save total record retrieved in a private variable, e.g.

void DataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs
e)
{
iTotalRecords = ((DataView)e.ReturnValue).Count;
}

Then I would subscribe to the rowCreated event to compose a message from the
pageIndex, pageSize and the total records count, e.g.

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
Label lbl= new Label();
//compse the label text
lbl.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " + ((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//notice that the pager template renders one cell in which
//there is an HTMLTable
e.Row.Cells[0].Controls.Add(lbl);
}
}

I haven't run this code, you might have to debug any typos in it, but it
should give you the idea.


--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

I have a girdview with paging enabled. How can I add a message in the footer
to say "Viewing records 1-15 of 45" etc

Thanks
 
G

Guest

Strange, I copied that coed directly and it still displays 2 new cells to the
right of the grid on their own. Looking at the generated HTML the pager
generates this....its hard to read here but the first cell has a colspan of
11 regardless of the code that reduces it. Maybe this just isnt going to work!

<tr align="left"
style="color:#000066;background-color:Gainsboro;font-family:Verdana;font-size:7pt;text-decoration:none;height:0px;">
<td colspan="11"><table border="0">
<tr>
<td><input type="image" src="images/GridView/grid_Next.png"
onclick="javascript:__doPostBack('ctl00$ContentPlaceHolder1$dgStaff','Page$Next')"
style="border-width:0px;" /></td><td><input type="image"
src="images/GridView/grid_Last.png"
onclick="javascript:__doPostBack('ctl00$ContentPlaceHolder1$dgStaff','Page$Last')" style="border-width:0px;" /></td>
</tr>
</table></td><td class="Label1">Viewing page 1 of 2</td><td><a
href="default.aspx">Reset</a></td>
</tr>
</table>

Phillip Williams said:
Compare your code to the code attached to this demo (at the bottom of the
demo there are 2 tabs; one for code in VB and another for the same code in C#)
http://www.webswapp.com/codesamples/aspnet20/gridview_multiplerows_selection/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


NH said:
Hi again,

I am having a bit of trouble getting this to work. I have the following code
in the grdiview rowcreated event...

If (e.Row.RowType = DataControlRowType.Pager) Then

Dim lbl = New Label()

lbl.Text = "Viewing page " & dgStaff.PageIndex + 1 & " of " &
dgStaff.PageCount
'notice that the pager template renders one cell in which
'there is an HTMLTable

Dim td As TableCell = New TableCell()

e.Row.Cells(0).ColumnSpan = e.Row.Cells(0).ColumnSpan -1
e.Row.Cells(0).Controls.Add(lbl)
'add the newly created cell to the same row as the pager

e.Row.Cells.Add(td)
e.Row.Cells(1).Text = "TEST"

End If

But the new cell is added outside of the width of the gridview, it is a
single new cell on the outside of the right side of the gridview.

I've been playing around with this trying to get it to work but with no
luck, any ideas?
thanks

Phillip Williams said:
The pager template renders a cell spanning the columns of the GridView. You
can change that columnspan to add a new tablecell on the same row where you
insert your new control. For example:

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
TableCell td = new TableCell();
//compse the tablecell's text
td.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " +
((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//decrease the colspan of the pager cell by 1 to add the new
tablecell
e.Row.Cells[0].ColumnSpan --;
//add the newly created cell to the same row as the pager
e.Row.Cells.Add(td);
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

I got it working nicely, thanks. I decided to show a message of "Viewing page
1 of 2" etc.

Is there a way of controlling where the label control is placed in the pager
template? It defaults to positioning itself under some other images I have
already added to the pager setting for navigating between pages. If I wanted
to add the label control to the far right hand side of the pager template, is
there a way to do that?

:

Thanks Philip,

I will try this out.
N

:

I would have a method subscribing to the Selected event of the datasource
object to save total record retrieved in a private variable, e.g.

void DataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs
e)
{
iTotalRecords = ((DataView)e.ReturnValue).Count;
}

Then I would subscribe to the rowCreated event to compose a message from the
pageIndex, pageSize and the total records count, e.g.

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
Label lbl= new Label();
//compse the label text
lbl.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " + ((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//notice that the pager template renders one cell in which
//there is an HTMLTable
e.Row.Cells[0].Controls.Add(lbl);
}
}

I haven't run this code, you might have to debug any typos in it, but it
should give you the idea.


--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

I have a girdview with paging enabled. How can I add a message in the footer
to say "Viewing records 1-15 of 45" etc

Thanks
 
G

Guest

Without seeing the other components in your GridView I cannot tell why is it
not working in your case. But here is another alternative that once Steven
Cheng recommended in a similar discussion, try it
http://groups.google.ca/group/micro...spnet.webcontrols/msg/e0182c9ca7b425df?hl=en&
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


NH said:
Strange, I copied that coed directly and it still displays 2 new cells to the
right of the grid on their own. Looking at the generated HTML the pager
generates this....its hard to read here but the first cell has a colspan of
11 regardless of the code that reduces it. Maybe this just isnt going to work!

<tr align="left"
style="color:#000066;background-color:Gainsboro;font-family:Verdana;font-size:7pt;text-decoration:none;height:0px;">
<td colspan="11"><table border="0">
<tr>
<td><input type="image" src="images/GridView/grid_Next.png"
onclick="javascript:__doPostBack('ctl00$ContentPlaceHolder1$dgStaff','Page$Next')"
style="border-width:0px;" /></td><td><input type="image"
src="images/GridView/grid_Last.png"
onclick="javascript:__doPostBack('ctl00$ContentPlaceHolder1$dgStaff','Page$Last')" style="border-width:0px;" /></td>
</tr>
</table></td><td class="Label1">Viewing page 1 of 2</td><td><a
href="default.aspx">Reset</a></td>
</tr>
</table>

Phillip Williams said:
Compare your code to the code attached to this demo (at the bottom of the
demo there are 2 tabs; one for code in VB and another for the same code in C#)
http://www.webswapp.com/codesamples/aspnet20/gridview_multiplerows_selection/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


NH said:
Hi again,

I am having a bit of trouble getting this to work. I have the following code
in the grdiview rowcreated event...

If (e.Row.RowType = DataControlRowType.Pager) Then

Dim lbl = New Label()

lbl.Text = "Viewing page " & dgStaff.PageIndex + 1 & " of " &
dgStaff.PageCount
'notice that the pager template renders one cell in which
'there is an HTMLTable

Dim td As TableCell = New TableCell()

e.Row.Cells(0).ColumnSpan = e.Row.Cells(0).ColumnSpan -1
e.Row.Cells(0).Controls.Add(lbl)
'add the newly created cell to the same row as the pager

e.Row.Cells.Add(td)
e.Row.Cells(1).Text = "TEST"

End If

But the new cell is added outside of the width of the gridview, it is a
single new cell on the outside of the right side of the gridview.

I've been playing around with this trying to get it to work but with no
luck, any ideas?
thanks

:

The pager template renders a cell spanning the columns of the GridView. You
can change that columnspan to add a new tablecell on the same row where you
insert your new control. For example:

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
TableCell td = new TableCell();
//compse the tablecell's text
td.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " +
((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//decrease the colspan of the pager cell by 1 to add the new
tablecell
e.Row.Cells[0].ColumnSpan --;
//add the newly created cell to the same row as the pager
e.Row.Cells.Add(td);
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

I got it working nicely, thanks. I decided to show a message of "Viewing page
1 of 2" etc.

Is there a way of controlling where the label control is placed in the pager
template? It defaults to positioning itself under some other images I have
already added to the pager setting for navigating between pages. If I wanted
to add the label control to the far right hand side of the pager template, is
there a way to do that?

:

Thanks Philip,

I will try this out.
N

:

I would have a method subscribing to the Selected event of the datasource
object to save total record retrieved in a private variable, e.g.

void DataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs
e)
{
iTotalRecords = ((DataView)e.ReturnValue).Count;
}

Then I would subscribe to the rowCreated event to compose a message from the
pageIndex, pageSize and the total records count, e.g.

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
Label lbl= new Label();
//compse the label text
lbl.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " + ((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//notice that the pager template renders one cell in which
//there is an HTMLTable
e.Row.Cells[0].Controls.Add(lbl);
}
}

I haven't run this code, you might have to debug any typos in it, but it
should give you the idea.


--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

I have a girdview with paging enabled. How can I add a message in the footer
to say "Viewing records 1-15 of 45" etc

Thanks
 
G

Guest

Thanks again Philip for your help, I will try it out.

Phillip Williams said:
Without seeing the other components in your GridView I cannot tell why is it
not working in your case. But here is another alternative that once Steven
Cheng recommended in a similar discussion, try it:
http://groups.google.ca/group/micro...spnet.webcontrols/msg/e0182c9ca7b425df?hl=en&
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


NH said:
Strange, I copied that coed directly and it still displays 2 new cells to the
right of the grid on their own. Looking at the generated HTML the pager
generates this....its hard to read here but the first cell has a colspan of
11 regardless of the code that reduces it. Maybe this just isnt going to work!

<tr align="left"
style="color:#000066;background-color:Gainsboro;font-family:Verdana;font-size:7pt;text-decoration:none;height:0px;">
<td colspan="11"><table border="0">
<tr>
<td><input type="image" src="images/GridView/grid_Next.png"
onclick="javascript:__doPostBack('ctl00$ContentPlaceHolder1$dgStaff','Page$Next')"
style="border-width:0px;" /></td><td><input type="image"
src="images/GridView/grid_Last.png"
onclick="javascript:__doPostBack('ctl00$ContentPlaceHolder1$dgStaff','Page$Last')" style="border-width:0px;" /></td>
</tr>
</table></td><td class="Label1">Viewing page 1 of 2</td><td><a
href="default.aspx">Reset</a></td>
</tr>
</table>

Phillip Williams said:
Compare your code to the code attached to this demo (at the bottom of the
demo there are 2 tabs; one for code in VB and another for the same code in C#)
http://www.webswapp.com/codesamples/aspnet20/gridview_multiplerows_selection/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

Hi again,

I am having a bit of trouble getting this to work. I have the following code
in the grdiview rowcreated event...

If (e.Row.RowType = DataControlRowType.Pager) Then

Dim lbl = New Label()

lbl.Text = "Viewing page " & dgStaff.PageIndex + 1 & " of " &
dgStaff.PageCount
'notice that the pager template renders one cell in which
'there is an HTMLTable

Dim td As TableCell = New TableCell()

e.Row.Cells(0).ColumnSpan = e.Row.Cells(0).ColumnSpan -1
e.Row.Cells(0).Controls.Add(lbl)
'add the newly created cell to the same row as the pager

e.Row.Cells.Add(td)
e.Row.Cells(1).Text = "TEST"

End If

But the new cell is added outside of the width of the gridview, it is a
single new cell on the outside of the right side of the gridview.

I've been playing around with this trying to get it to work but with no
luck, any ideas?
thanks

:

The pager template renders a cell spanning the columns of the GridView. You
can change that columnspan to add a new tablecell on the same row where you
insert your new control. For example:

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
TableCell td = new TableCell();
//compse the tablecell's text
td.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " +
((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//decrease the colspan of the pager cell by 1 to add the new
tablecell
e.Row.Cells[0].ColumnSpan --;
//add the newly created cell to the same row as the pager
e.Row.Cells.Add(td);
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

I got it working nicely, thanks. I decided to show a message of "Viewing page
1 of 2" etc.

Is there a way of controlling where the label control is placed in the pager
template? It defaults to positioning itself under some other images I have
already added to the pager setting for navigating between pages. If I wanted
to add the label control to the far right hand side of the pager template, is
there a way to do that?

:

Thanks Philip,

I will try this out.
N

:

I would have a method subscribing to the Selected event of the datasource
object to save total record retrieved in a private variable, e.g.

void DataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs
e)
{
iTotalRecords = ((DataView)e.ReturnValue).Count;
}

Then I would subscribe to the rowCreated event to compose a message from the
pageIndex, pageSize and the total records count, e.g.

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
Label lbl= new Label();
//compse the label text
lbl.Text="Viewing records " + (GridView1.PageIndex *
GridView1.PageSize) +1 + " - " + ((GridView1.PageIndex+1) *
GridView1.PageSize) +" of " + iTotalRecords ;
//notice that the pager template renders one cell in which
//there is an HTMLTable
e.Row.Cells[0].Controls.Add(lbl);
}
}

I haven't run this code, you might have to debug any typos in it, but it
should give you the idea.


--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

I have a girdview with paging enabled. How can I add a message in the footer
to say "Viewing records 1-15 of 45" etc

Thanks
 

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,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top