I have a trick to do that!
this is my template code for a dropdownlist:
<asp:TemplateField HeaderText="Menu Group"
SortExpression="Category">
<EditItemTemplate>
<asp

ropDownList
ID="ddEditCategory" runat="server"
ValidationGroup='<%# Bind("Category") %>'
OnDataBound="ddEditCategory_DataBound"
DataSource
="<%#odsPageGroupList%>"
DataTextField="Category" DataValueField="Category" >
</asp

ropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2"
runat="server" Text='<%# Bind("Category") %>'></asp:Label>
</ItemTemplate>
I cheated by puting the value of the Category value, the text value, in the
ValidationGroup proeprty.
Then in the OnDataBound event for the dropdownlist
(ddEditCategory_DataBound) I have this code:
protected void ddEditCategory_DataBound(object sender, EventArgs e)
{
((DropDownList)sender).SelectedIndex =
((DropDownList)sender).Items.IndexOf(((DropDownLis t)sender).Items.FindByText(((DropDownList)sender). ValidationGroup));
}
Now some people may scream a this so if that is the case you can add a
property of your to a control that you create that inhertis from the
dropdownlist and go through all the hoops, but this is a quick and dirty (and
i mean Dirty) way to do what you want!
Hope this helps!
"paul.haines (AT) wcbs (DOT) co.uk" wrote:
Quote:
I have a DetailsView with a number of TemplateFields, (plus other
types of fields). One has a button and a click event handler. Another
has DropDownList, which has its selected value initialised when
editing, (from a session variable source).
Unfortunately I've found that to get the click event to fire I need to
re-bind the DetailsView when posting back the page, but this loses the
newly selected option in the DropDownList. If I don't re-bind then I
keep the chosen option, but the button's event never fires.
Any ideas what I can do to solve this? Or have I done something wrong
with my current method?
Thanks for any help,
Paul |