J
J055
Hi
I thought I was trying to do something very simple but I'm have a lot of
trouble trying to do the following.
<asp:FormView ID="fvGroups" runat="server" DataKeyNames="GroupID"
DataSourceID="odsGroups"
DefaultMode="Insert" Visible="false" OnItemCommand="fvGroups_ItemCommand">
<InsertItemTemplate>
<asp
ropDownList ID="ddlEditMode" runat="server"
OnInit="ddlEditMode_Init" SelectedValue='<%# Bind("EditMode") %>'>
<asp:ListItem Selected="True" Value="0" Text="Select..." ></asp:ListItem>
</asp
ropDownList>
</InsertItemTemplate>
</asp:FormView>
....
protected void ddlEditMode_Init(object sender, EventArgs e)
{
DropDownList ddlEditMode = sender as DropDownList;
ddlEditMode.EnableViewState = false;
ddlEditMode.AppendDataBoundItems = true;
ddlEditMode.DataSource = myList; // an OrderedDictionary object
ddlEditMode.DataTextField = "value";
ddlEditMode.DataValueField = "key";
// Bind the data to the control.
ddlEditMode.DataBind();
}
When I add SelectedValue='<%# Bind("EditMode") %>'> to the DroupDownList I
get this error.
"System.InvalidOperationException: Databinding methods such as Eval(),
XPath(), and Bind() can only be used in the context of a databound control."
I just want to save the value to the ObjectDataSource InsertParameters.
Surely this is a very standard requirement?
Thanks
Andrew
I thought I was trying to do something very simple but I'm have a lot of
trouble trying to do the following.
<asp:FormView ID="fvGroups" runat="server" DataKeyNames="GroupID"
DataSourceID="odsGroups"
DefaultMode="Insert" Visible="false" OnItemCommand="fvGroups_ItemCommand">
<InsertItemTemplate>
<asp

OnInit="ddlEditMode_Init" SelectedValue='<%# Bind("EditMode") %>'>
<asp:ListItem Selected="True" Value="0" Text="Select..." ></asp:ListItem>
</asp

</InsertItemTemplate>
</asp:FormView>
....
protected void ddlEditMode_Init(object sender, EventArgs e)
{
DropDownList ddlEditMode = sender as DropDownList;
ddlEditMode.EnableViewState = false;
ddlEditMode.AppendDataBoundItems = true;
ddlEditMode.DataSource = myList; // an OrderedDictionary object
ddlEditMode.DataTextField = "value";
ddlEditMode.DataValueField = "key";
// Bind the data to the control.
ddlEditMode.DataBind();
}
When I add SelectedValue='<%# Bind("EditMode") %>'> to the DroupDownList I
get this error.
"System.InvalidOperationException: Databinding methods such as Eval(),
XPath(), and Bind() can only be used in the context of a databound control."
I just want to save the value to the ObjectDataSource InsertParameters.
Surely this is a very standard requirement?
Thanks
Andrew