Hi
I thought calling ObjectDataSource.Select() gives the same results as calling ObjectDataSource.DataBind(), but in some cases that doesn’t seem to be true:
<asp:ObjectDataSource ID="ODS1" TypeName="PersonDB" SelectMethod="GetPeople"
runat="server"></asp:ObjectDataSource>
<br>
<asp:ListBox ID="ListBox1" DataSourceID="ODS1" DataTextField="PersonID"
AutoPostBack="true" runat="server"></asp:ListBox>
<br>
<asp:ObjectDataSource ID="ODS2" InsertMethod="InsertEmployee"
TypeName="PersonDB" SelectMethod="GetPerson" runat="server">
<SelectParameters>
<asp:ControlParameter ConvertEmptyStringToNull="True" Name="PersonID"
PropertyName="SelectedValue" ControlID="ListBox1" />
</SelectParameters>
</asp:ObjectDataSource>
<br>
<asp:DetailsView ID="DetailsView1" AutoGenerateInsertButton="true" DataSourceID="ODS2"
runat="server"> </asp:DetailsView>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ODS1.Select(); //same as calling ODS1.DataBind();
}
if (IsPostBack)
{
ODS2.Select(); // returns no results
}
}
In the above code calling ODS1.Select() produces the same results as calling ODS1.DataBind(). But if on postback user selects an item in ListBox, ODS2.Select() still doesn’t return any results, but if we replace ODS2.Select(); with ODS2.DataBind(); then a row is returned. So why doesn’t ODS2.Select(); return any results, but ODS2.DataBind(); does?
thank you
EDIT:
Assuming user select an item in a Listbox --> It seems that when we call ODS2.Select(), ODS2 for some reason can't bind to ListBox1.SelectedValue and extract a value from this property