Adding attributes to page button of datagrid

  • Thread starter Thread starter sumit
  • Start date Start date
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
 
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
 
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
.
.
 
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
.
.
.
 
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
.

.
.
.
 
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
.

.
.
.
 
Back
Top