Pager and Event Handling

  • Thread starter Thread starter sunil
  • Start date Start date
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
 
What are you doing in your onclick method? It appears as if the issue is in
the handler, not in the creation.
 
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
 
Back
Top