Pager and Event Handling

S

sunil

OnItemCreated method of DataGrid I modified the Pager cell to have a button

TableCell pager = (TableCell)e.Item.Controls[0];
ImageButton hImg = new ImageButton();
hImg.ImageAlign=ImageAlign.Left;
hImg.ImageUrl="some.gif";
hImg.CommandName="SomeCommand";
pager.Controls.AddAt(0,hImg);

When i click on the ImageButton I get:
Object reference not set to an instance of an object
How can i handle the event from this Button.
Appreciate any help. Thanks
 
C

Chris Jackson

What are you doing in your onclick method? It appears as if the issue is in
the handler, not in the creation.
 
S

sunil

Thanks Chris!!.Appreciate your reply
The ImageButton is not part of the aspx page. It is created dynamically and
added to the pager row.
How do i write onclick handler for it.?
i tried something like this.

hImg.Attributes["onclick"]="javascript:__doPostBack('"+DataGrid1.ClientID+"'
,'');";
but my OnItemCommand handler of datagrid is not called.



Chris Jackson said:
What are you doing in your onclick method? It appears as if the issue is in
the handler, not in the creation.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows XP
Windows XP Associate Expert
--
sunil said:
OnItemCreated method of DataGrid I modified the Pager cell to have a button

TableCell pager = (TableCell)e.Item.Controls[0];
ImageButton hImg = new ImageButton();
hImg.ImageAlign=ImageAlign.Left;
hImg.ImageUrl="some.gif";
hImg.CommandName="SomeCommand";
pager.Controls.AddAt(0,hImg);

When i click on the ImageButton I get:
Object reference not set to an instance of an object
How can i handle the event from this Button.
Appreciate any help. 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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top