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 to SelectedValue which is expected to be Int32. If you now look at the markup for classCode, you're binding to SelectedValue.Text on the same object. We know from the first instance that SelectedValue is Int32 which doesn't have a property called Text. You'll need to correct your binding to the correct object and property type.
Based on the code above, the ObjectDataSource will not be able to pick out the text from SelectedItem.Text. In order to get around this, you need to modify the ObjectDataSource to have a Selecting event like so;
<asp:ObjectDataSource ID="odsInsert" runat="server" SelectMethod="GetStudentInClass2"
TypeName="MIHE_MIS.DALS.MidTermExamResultDAL"
OnSelecting="odsInsert_Selecting">
<SelectParameters>
<asp:Parameter Name="classCode" 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>
Then in your code behind you'd have the event declared;
protected void odsInsert_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
e.InputParameters["classCode"] = ddlClasses.SelectedItem.Text;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With