Droplist in header template

  • Thread starter Thread starter NerdRunner
  • Start date Start date
N

NerdRunner

Hello group,

I am using a data grid with template columns. I have a drop list in
the header of the template column that will allow users to select a
value for filtering of the data in the grid. When would I populate the
drop list?

Sean M. Severson
 
I have tried populating the drop lists on the Page_Load event, but I am
unable to get the drop list control. I am using
dgUsers.FindControl("ddlAccount") and it is not finding the control. I
have also tried dgUsers.Items(1).FindControl("ddlAccount") without any
luck.

Sean M. Severson

Eliyahu said:
In the Page_Load event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


NerdRunner said:
Hello group,

I am using a data grid with template columns. I have a drop list in
the header of the template column that will allow users to select a
value for filtering of the data in the grid. When would I populate the
drop list?

Sean M. Severson
 
Ok, I thing my first advice was not correct.

Since the ddl is inside the header, you need to call the FindControl method
on the item representing the header.

dgUsers.FindControl("ddlAccount") is obviously not good because it doesn't
get inside any item.

dgUsers.Items(1).FindControl("ddlAccount") is not good either because Items
collection doesn't include the header item.

You can catch the header item in either ItemCreated or ItemDataBound event.
Use ItemType property to tell the header item. Once you have got the item,
call FindControl("ddlAccount") on the item instance.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


NerdRunner said:
I have tried populating the drop lists on the Page_Load event, but I am
unable to get the drop list control. I am using
dgUsers.FindControl("ddlAccount") and it is not finding the control. I
have also tried dgUsers.Items(1).FindControl("ddlAccount") without any
luck.

Sean M. Severson

Eliyahu said:
In the Page_Load event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


NerdRunner said:
Hello group,

I am using a data grid with template columns. I have a drop list in
the header of the template column that will allow users to select a
value for filtering of the data in the grid. When would I populate the
drop list?

Sean M. Severson
 
I believe your advice will help me, but I am getting an error on the
DataBind action on the data grid. This appears to be due to using a
function that creates a new datareader, populates the drop list
control, and then closes the datareader. The error I get is Invalid
attempt to FieldCount when reader is closed.

Can I have only one reader on a connection open at a time? Are all
readers closed when another reader is opened?

Sean M. Severson

Eliyahu said:
Ok, I thing my first advice was not correct.

Since the ddl is inside the header, you need to call the FindControl method
on the item representing the header.

dgUsers.FindControl("ddlAccount") is obviously not good because it doesn't
get inside any item.

dgUsers.Items(1).FindControl("ddlAccount") is not good either because Items
collection doesn't include the header item.

You can catch the header item in either ItemCreated or ItemDataBound event.
Use ItemType property to tell the header item. Once you have got the item,
call FindControl("ddlAccount") on the item instance.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


NerdRunner said:
I have tried populating the drop lists on the Page_Load event, but I am
unable to get the drop list control. I am using
dgUsers.FindControl("ddlAccount") and it is not finding the control. I
have also tried dgUsers.Items(1).FindControl("ddlAccount") without any
luck.

Sean M. Severson

Eliyahu said:
In the Page_Load event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Hello group,

I am using a data grid with template columns. I have a drop list in
the header of the template column that will allow users to select a
value for filtering of the data in the grid. When would I populate the
drop list?

Sean M. Severson
 
I believe your advice will help me, but I am getting an error on the
DataBind action on the data grid. This appears to be due to using a
function that creates a new datareader, populates the drop list
control, and then closes the datareader. The error I get is Invalid
attempt to FieldCount when reader is closed.

Can I have only one reader on a connection open at a time? Are all
readers closed when another reader is opened?

Sean M. Severson

Eliyahu said:
Ok, I thing my first advice was not correct.

Since the ddl is inside the header, you need to call the FindControl method
on the item representing the header.

dgUsers.FindControl("ddlAccount") is obviously not good because it doesn't
get inside any item.

dgUsers.Items(1).FindControl("ddlAccount") is not good either because Items
collection doesn't include the header item.

You can catch the header item in either ItemCreated or ItemDataBound event.
Use ItemType property to tell the header item. Once you have got the item,
call FindControl("ddlAccount") on the item instance.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


NerdRunner said:
I have tried populating the drop lists on the Page_Load event, but I am
unable to get the drop list control. I am using
dgUsers.FindControl("ddlAccount") and it is not finding the control. I
have also tried dgUsers.Items(1).FindControl("ddlAccount") without any
luck.

Sean M. Severson

Eliyahu said:
In the Page_Load event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Hello group,

I am using a data grid with template columns. I have a drop list in
the header of the template column that will allow users to select a
value for filtering of the data in the grid. When would I populate the
drop list?

Sean M. Severson
 
If you databind to a datareader, it has to be open at the time when you call
the DataBind method. It is hard to say anything more specific without seeing
the code.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

NerdRunner said:
I believe your advice will help me, but I am getting an error on the
DataBind action on the data grid. This appears to be due to using a
function that creates a new datareader, populates the drop list
control, and then closes the datareader. The error I get is Invalid
attempt to FieldCount when reader is closed.

Can I have only one reader on a connection open at a time? Are all
readers closed when another reader is opened?

Sean M. Severson

Eliyahu said:
Ok, I thing my first advice was not correct.

Since the ddl is inside the header, you need to call the FindControl method
on the item representing the header.

dgUsers.FindControl("ddlAccount") is obviously not good because it doesn't
get inside any item.

dgUsers.Items(1).FindControl("ddlAccount") is not good either because Items
collection doesn't include the header item.

You can catch the header item in either ItemCreated or ItemDataBound event.
Use ItemType property to tell the header item. Once you have got the item,
call FindControl("ddlAccount") on the item instance.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


NerdRunner said:
I have tried populating the drop lists on the Page_Load event, but I am
unable to get the drop list control. I am using
dgUsers.FindControl("ddlAccount") and it is not finding the control. I
have also tried dgUsers.Items(1).FindControl("ddlAccount") without any
luck.

Sean M. Severson

Eliyahu Goldin wrote:
In the Page_Load event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Hello group,

I am using a data grid with template columns. I have a drop list in
the header of the template column that will allow users to select a
value for filtering of the data in the grid. When would I
populate
the
drop list?

Sean M. Severson
 
Back
Top