Adding attributes to page button of datagrid

S

sumit

Hi,

I want to add one java script function on the click of
page button of datagrid. But how to get UI control of page
button so that i should be able to add attribute for
onClick event.

Please suggest

Sumit
 
A

alex bowers

Hi Sumit

in the Item_Created event of the datagrid you can trap
the iteration for when the Pager row item is created using
[C#]
if (e.Item.ItemType == ListItemType.Pager)

the way asp.net renders the pager row to the browser can
vary - it usually creates a single table-cell and fills
this cell with controls containing the paging buttons.

To extract the attributes collection of the control you
want to access you can use
[C#]
e.Item.Cells[index].Controls[index].Attributes

or e.Item.Cells[index].FindControl(name)


alex
 
S

sumit

Hi Alex,

Thanks a lot!
I tried the same thing in DataItembound event of datagrid
but it If condition falied there,,,

Is DataItembound doesnt get Pager item and Item_Created
can have that item??

Please suggest
-----Original Message-----
Hi Sumit

in the Item_Created event of the datagrid you can trap
the iteration for when the Pager row item is created using
[C#]
if (e.Item.ItemType == ListItemType.Pager)

the way asp.net renders the pager row to the browser can
vary - it usually creates a single table-cell and fills
this cell with controls containing the paging buttons.

To extract the attributes collection of the control you
want to access you can use
[C#]
e.Item.Cells[index].Controls[index].Attributes

or e.Item.Cells[index].FindControl(name)


alex
-----Original Message-----
Hi,

I want to add one java script function on the click of
page button of datagrid. But how to get UI control of page
button so that i should be able to add attribute for
onClick event.

Please suggest

Sumit
.
.
 
A

alex bowers

yes, the ItemDataBound event doesn't trap the pager item -
you need to use the ItemCreated event.

alex
-----Original Message-----
Hi Alex,

Thanks a lot!
I tried the same thing in DataItembound event of datagrid
but it If condition falied there,,,

Is DataItembound doesnt get Pager item and Item_Created
can have that item??

Please suggest
-----Original Message-----
Hi Sumit

in the Item_Created event of the datagrid you can trap
the iteration for when the Pager row item is created using
[C#]
if (e.Item.ItemType == ListItemType.Pager)

the way asp.net renders the pager row to the browser can
vary - it usually creates a single table-cell and fills
this cell with controls containing the paging buttons.

To extract the attributes collection of the control you
want to access you can use
[C#]
e.Item.Cells[index].Controls[index].Attributes

or e.Item.Cells[index].FindControl(name)


alex
-----Original Message-----
Hi,

I want to add one java script function on the click of
page button of datagrid. But how to get UI control of page
button so that i should be able to add attribute for
onClick event.

Please suggest

Sumit
.
.
.
 
S

sumit

Yes, Now in Item_Created event, If conditions goes well
but it gives only one cell and one control for that i.e
Label,,but i need to get that page button (1,2,3....)

the code is:

private void dgSearchedAltPackages_ItemCreated(object
sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Pager )
{
foreach(Control ctrl in e.Item.Controls)
{
Response.Write("ctrl type" + ((Label)ctrl.Controls
[0]).GetType() +"<br>");
}
}
}

It prints only Label and no Button UI type??

Please suggest!!

Thanks,
Sumit
-----Original Message-----
yes, the ItemDataBound event doesn't trap the pager item -
you need to use the ItemCreated event.

alex
-----Original Message-----
Hi Alex,

Thanks a lot!
I tried the same thing in DataItembound event of datagrid
but it If condition falied there,,,

Is DataItembound doesnt get Pager item and Item_Created
can have that item??

Please suggest
-----Original Message-----
Hi Sumit

in the Item_Created event of the datagrid you can trap
the iteration for when the Pager row item is created using
[C#]
if (e.Item.ItemType == ListItemType.Pager)

the way asp.net renders the pager row to the browser can
vary - it usually creates a single table-cell and fills
this cell with controls containing the paging buttons.

To extract the attributes collection of the control you
want to access you can use
[C#]
e.Item.Cells[index].Controls[index].Attributes

or e.Item.Cells[index].FindControl(name)


alex
-----Original Message-----
Hi,

I want to add one java script function on the click of
page button of datagrid. But how to get UI control of
page
button so that i should be able to add attribute for
onClick event.

Please suggest

Sumit
.

.
.
.
 
S

sumit

Hi,

Thanks a lot!!
It is done!!

Sumit
-----Original Message-----
yes, the ItemDataBound event doesn't trap the pager item -
you need to use the ItemCreated event.

alex
-----Original Message-----
Hi Alex,

Thanks a lot!
I tried the same thing in DataItembound event of datagrid
but it If condition falied there,,,

Is DataItembound doesnt get Pager item and Item_Created
can have that item??

Please suggest
-----Original Message-----
Hi Sumit

in the Item_Created event of the datagrid you can trap
the iteration for when the Pager row item is created using
[C#]
if (e.Item.ItemType == ListItemType.Pager)

the way asp.net renders the pager row to the browser can
vary - it usually creates a single table-cell and fills
this cell with controls containing the paging buttons.

To extract the attributes collection of the control you
want to access you can use
[C#]
e.Item.Cells[index].Controls[index].Attributes

or e.Item.Cells[index].FindControl(name)


alex
-----Original Message-----
Hi,

I want to add one java script function on the click of
page button of datagrid. But how to get UI control of
page
button so that i should be able to add attribute for
onClick event.

Please suggest

Sumit
.

.
.
.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top