DropDownList is empty on the Insert click of the FormView

Sep 19, 2007 at 10:32 AM
Hi all,

I have the DropDownList in the FormView,inside InsertTemplateField
The data is binded in run time to it in codebehind page,FOr the First time the page is loaded
the DropdownList is not empty.
when i click on the insert Link the data should be displayed in the gridView (Which is below the formview),
But when i click on the Insert link the data is displayed in the gridView,
But the DropdownList is empty.

Here is the Code Html
====================================

<asp:FormView id="FormViewEducation" runat="server" Width="100%" DataSourceID="EducationObjectContainerDataSource" DefaultMode="Insert" DataKeyNames="CollegeId">
<InsertItemTemplate>

<table width="100%">
<tr>
<td style="width:20%;"> Institute:
</td>
<td style="width:30%;">
<asp:DropDownList ID="CandidateEducationInstitute" runat="server" Width="100%">
</asp:DropDownList>
</td>

</tr>
</table>
</InsertItemTemplate>
</asp:FormView>

<asp:GridView ID="EducationGridView" runat="server" AutoGenerateColumns="False" AllowSorting="True" >
<Columns>
<asp:BoundField DataField="CollegeText" HeaderText="Institute" SortExpression="CollegeId" />
</Columns>
</asp:GridView>

===========================================

Here is the code Behind Page
========================================

private void ConfigureEducationDropDownLists()
{
DropDownList dropDownEducationInstitute = (DropDownList)this.FormView1.FindControl("CandidateEducationInstitute");
dropDownEducationInstitute.DataSource = _catalogCollection1.CatalogValueCollection;
dropDownEducationInstitute.DataMember = "CatalogValueCollection";
dropDownEducationInstitute.DataTextField = "Value";
dropDownEducationInstitute.DataValueField = "Id";
dropDownEducationInstitute.DataBind();
}

===================================================

I tried this funcation Calling inside ispostBack & outside the isPostback in the PageLoad
But still the data is empty on insert Link click.

Here is the code on the Insert Click of formView
===========================================================

protected void EducationObjectContainerDataSource_Inserted(object sender, Microsoft.Practices.Web.UI.WebControls.ObjectContainerDataSourceStatusEventArgs e)
{
CandidateEducationProfileCollection educationValueCollection = (CandidateEducationProfileCollection)Session"educationValueCollection";
DropDownList dropDownEducationInstitute = (DropDownList)this.FormView1.FindControl("FormViewEducation$CandidateEducationInstitute");
candidateEducation.CollegeId = int.Parse(dropDownEducationInstitute.SelectedValue.ToString());
educationValueCollection.Add(candidateEducation);
gridEducation.DataSource = educationValueCollection;
gridEducation.DataBind();
}
=============================================================

The two-way dataBinding is also not working , When is <asp:DropDownList ID="CandidateEducationInstitute" runat="server" Width="100%" selectedValue='<%# Bind("InstitueId")%>'>

I get the error
----------------------------

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control



I am not getting were is the problem,

Thanks with Regards
Anil S