This error happens when I use the SelectedItem.Text of a dropdownlist as a value to pass for ObjectDataSource.
Here is the markup
<asp:ObjectDataSource ID="odsInsert" runat="server" SelectMethod="GetStudentInClass2" TypeName="MIHE_MIS.DALS.MidTermExamResultDAL">
<SelectParameters>
<asp:ControlParameter DefaultValue="" ControlID="ddlClasses" Name="classCode" PropertyName="SelectedItem.Text" Type="String" />
<asp:ControlParameter ControlID="ddlSemesters" Name="semesterID" PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter ControlID="ddlSpecialization" Name="specializationID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
Moreover, I add the Select Class text the dropdownlist dynamically.
protected void ddlClasses_DataBound(object sender, EventArgs e)
{
ListItem list = new ListItem("Select Class", "-1");
this.ddlClasses.Items.Insert(0, list);
}
If you look at the markup for
semesterID, it's binding toSelectedValuewhich is expected to beInt32. If you now look at the markup forclassCode, you're binding toSelectedValue.Texton the same object. We know from the first instance thatSelectedValueisInt32which doesn't have a property calledText. You'll need to correct your binding to the correct object and property type.Based on the code above, the
ObjectDataSourcewill not be able to pick out the text fromSelectedItem.Text. In order to get around this, you need to modify theObjectDataSourceto have aSelectingevent like so;Then in your code behind you'd have the event declared;