How to access dropdownlist inside iTemplate?

V

vicgroups

Hello,

I am adding columns to the datagrid programmatically. And I have
created a countries drop down list in an ascx file. I have added the
countries drop down list to the datagrid column as follows,

TemplateColumn tc = new TemplateColumn();
ITemplate iTemplate = LoadTemplate("DropDownList_Countries.ascx");
tc.EditItemTemplate = iTemplate;
DataGrid1.Columns.Add(tc);

The drop down list has been loaded successfully on the datagrid. And
now I want to set it to a value (according to the database binding).
Say, set to the value of Norway.

I have tried this but not successful:

DropDownList ddlCountry = (DropDownList)
DataGrid1.FindControl("DropDownListObject");
ddlCountry.SelectedValue = "Norway";

The error is "System.NullReferenceException: Object reference not set
to an instance of an object." (Probably the control cannot be found)

How can I access the dropdownlist object inside the iTemplate and set
its value?

I was looking into the instantiateIn method, but not sure how to fit
this into my case.

Thanks a lot.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top