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.
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.