By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,688 Members | 1,862 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,688 IT Pros & Developers. It's quick & easy.

gridview: "Viewing record x of y"

P: n/a
NH
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
Apr 10 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
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" wrote:
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

Apr 10 '06 #2

P: n/a
NH
Thanks Philip,

I will try this out.
N

"Phillip Williams" wrote:
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" wrote:
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

Apr 10 '06 #3

P: n/a
NH
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" wrote:
Thanks Philip,

I will try this out.
N

"Phillip Williams" wrote:
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" wrote:
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

Apr 11 '06 #4

P: n/a
NH
Thanks Philip, great insight.
Regards
N

"Phillip Williams" wrote:
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" wrote:
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" wrote:
Thanks Philip,

I will try this out.
N

"Phillip Williams" wrote:

> 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" wrote:
>
> > 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

Apr 11 '06 #5

P: n/a
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" wrote:
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" wrote:
Thanks Philip,

I will try this out.
N

"Phillip Williams" wrote:
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" wrote:

> 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

Apr 11 '06 #6

P: n/a
NH
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" wrote:
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" wrote:
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" wrote:
Thanks Philip,

I will try this out.
N

"Phillip Williams" wrote:

> 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" wrote:
>
> > 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

Apr 12 '06 #7

P: n/a
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/...n/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"NH" wrote:
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" wrote:
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" wrote:
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" wrote:

> Thanks Philip,
>
> I will try this out.
> N
>
> "Phillip Williams" wrote:
>
> > 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" wrote:
> >
> > > 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

Apr 13 '06 #8

P: n/a
NH
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$ContentPla ceHolder1$dgStaff','Page$Next')"
style="border-width:0px;" /></td><td><input type="image"
src="images/GridView/grid_Last.png"
onclick="javascript:__doPostBack('ctl00$ContentPla ceHolder1$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" wrote:
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/...n/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"NH" wrote:
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" wrote:
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" wrote:

> 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" wrote:
>
> > Thanks Philip,
> >
> > I will try this out.
> > N
> >
> > "Phillip Williams" wrote:
> >
> > > 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" wrote:
> > >
> > > > 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

Apr 13 '06 #9

P: n/a
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/micros...7b425df?hl=en&
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"NH" wrote:
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$ContentPla ceHolder1$dgStaff','Page$Next')"
style="border-width:0px;" /></td><td><input type="image"
src="images/GridView/grid_Last.png"
onclick="javascript:__doPostBack('ctl00$ContentPla ceHolder1$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" wrote:
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/...n/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"NH" wrote:
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" wrote:

> 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" wrote:
>
> > 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" wrote:
> >
> > > Thanks Philip,
> > >
> > > I will try this out.
> > > N
> > >
> > > "Phillip Williams" wrote:
> > >
> > > > 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" wrote:
> > > >
> > > > > 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

Apr 13 '06 #10

P: n/a
NH
Thanks again Philip for your help, I will try it out.

"Phillip Williams" wrote:
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/micros...7b425df?hl=en&
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"NH" wrote:
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$ContentPla ceHolder1$dgStaff','Page$Next')"
style="border-width:0px;" /></td><td><input type="image"
src="images/GridView/grid_Last.png"
onclick="javascript:__doPostBack('ctl00$ContentPla ceHolder1$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" wrote:
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/...n/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"NH" wrote:

> 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" wrote:
>
> > 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" wrote:
> >
> > > 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" wrote:
> > >
> > > > Thanks Philip,
> > > >
> > > > I will try this out.
> > > > N
> > > >
> > > > "Phillip Williams" wrote:
> > > >
> > > > > 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" wrote:
> > > > >
> > > > > > 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

Apr 13 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.