Customizing pager/header/footer

T

Tumurbaatar S.

I need to put web controls inside pager, header or footer
parts of the datagrid. Any ideas?
 
T

Tumurbaatar S.

Thank you!
I've added controls to my datagrid's footer and pager. And now I can
customize them at item's Create or DataBound events. But I cannot find
a method to access these controls after, for example, after postback.
DataGrid.Items contains only normal item rows. The header/footer/pagers
are not included in this collection. My datagrid has several controls
on the footer row and I do postback using some button. And within
this button's Click event handler I need to examine content of these
controls. Any ideas?
Also, in several articles about adding controls to the pager, for example,
I saw that before dynamically adding a control, authors check out whether
this control was added in prior round trips. They says that the datagrid
can save previously added control and without checking this, it may
lead to duplicate controls. In my code I don't check it and all work
normally: no duplicated/doubled controls. Anybody can explain this?
 
T

Tumurbaatar S.

From MSDN/.NET Reference:
"...Note Only items bound to the data source are contained in the
Items collection. The header, footer, and separator are not included in
the collection....".

What collection do you mean?
 
A

alvinz_c

Hi, Tumurbaatar. You are right. Only data-bound items are included in the
Items collection. For instance, to accessing LinkButton control in the

1. Header
DataGridItem item = (DataGridItem)DataGrid1.Controls[0].Controls[0];
LinkButton lbtnHeader = (LinkButton)item.FindControl("lbtnInHeader");


1. Footer
DataGridItem item =
(DataGridItem)DataGrid1.Controls[0].Controls[DataGrid1.Controls[0].Controls.Count-2];
LinkButton lbtnFooter = (LinkButton)item.FindControl("lbtnInFooter");


1. Pager
DataGridItem item =
(DataGridItem)DataGrid1.Controls[0].Controls[DataGrid1.Controls[0].Controls.Count-1];
LinkButton lbtnPager = (LinkButton)item.FindControl("lbtnInPager");


The DataGrid1.Controls[0] refers to the DataGridTable in the page hierarchy
control tree. Take note that, if the pager is implemented, the footer is the
second last DataGridItem control, otherwise I would be the last one, always.


Hope this helps...
 
T

Tumurbaatar S.

Got an error: Specified argument was out of the range of valid values.
Parameter name: index.

On the 1st Page_Load event my DataGrid is empty.
DataGrid1.Controls.Count returns 0, i.e. DataGrid1.Controls[0]
does not exist.
Why?
There's a DropDownList in my DataGrid's footer and I need
to populate list items from the Page_Load().
Referencing DataGrid1.Controls[0] after postback works:
no exception raised, items populated normally.
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top