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() p开发者_如何学Pythonroduces 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
ODS2 has a Select parameter, which in your sample page load is bound to a ListBox control that hasn't been databound. What's in the ListBox? What is being passed in the PersonID parameter that is passed to ODS2?
The most obvious way to start answering your question would be to set a breakpoint in the GetPerson method of PersonDB and see what is being passed as parameters. Then follow the code to see what gets retrieved.
精彩评论