Why would a GridView control's RowUpdating/RowUpdated event arguments have NewValues == OldValues regardless of user input?
I've found the answer to this now after some poking and rearranging.
Seemingly it was a DataBind in page load that was resetting the new values to the old ones before the event handler. Should have guessed.... :)
Related
I'm new to asp.net trying to use datalist control.
on edititemtemplate section i have put up a dropdownlist control. It has values in it. What I want is to select a value in edit mode but when I go to event (as set in oneditcommand ) my codes cannot find dropdownlist though its in edititemtemplate. Please check my codes below
DropDownList ddl = e.Item.FindControl("ddlType") as DropDownList;
ddl.Items.FindByValue((e.Item.FindControl("lblType") as Label).Text).Selected = true;
What I'm doing wrong?
thanks
-Navi
take a look at this link. Typically, you access controls like this at runtime by handling either the DataList's ItemCreated or ItemDataBound event.
I have the control dropdownlist which has been loaded inside the template column of RadGrid.
While loading I have set AutoPostBack='True' for dropdownlist and also created the event SelectedIndexChanged.
DropDownList ddlConditions = new DropDownList();
ddlConditions.ID = "ddl" + name;
ddlConditions.AutoPostBack = true;
ddlConditions.SelectedIndexChanged += new EventHandler(ddlConditions_SelectedIndexChanged);
My question is while i change the selected index of dropdownlist the event SelectedIndexChanged is not getting triggered.
Can anyone help me to solve this problem?
Thanks in advance.
Usually this caused by a page life cycle problem. When your index changed event of Dropdownlist fires the control doesn't exist to bind it on the postback.
Example:
-> MyEvent fires.
-> Drop-down created.
-> Event Handler specified.
-> Index Changed event triggered. Page reloads. Drop-down not found, cannot fire.
So you have to ensure that the drop-down is created before .NET attempts to handle the event.
Please refer this answer for more information regarding this type of issue and life cycle.
I can suggest you to check the place where you have created DropDownList. Dynamic controls should be added on OnInit or at least on OnLoad. After OnLoad finishes executing ASP.NET starts processing control's events and values.
My question is while i change the selected index of dropdownlist the
event SelectedIndexChanged is not getting triggered.
Answer: because you have created DropDownList after the events have been processed.
Is the page posting back? If so, you'll need to make sure that the control is recreated on the page on every postback.
If it's inside the usual if(!IsPostBack) block, then put it outside - Usually, it's prudent to create controls in page_init as well, but that can depend on your specific setup.
So on the .NET GridView control there's a RowDataBound event, at which time I create a DropDownList for each row in a particular column.
When that DropDownList changes on the client, I can get it to post back, but the control's state is already gone. What's the best approach to handling events for controls created during the RowDataBound event?
I'm curious: why are you adding these DropDownLists to the GridView in the RowDataBound event? I genuinely can't think of a reason to do this.
Even if you have just a placeholder DropDownList in the original RowTemplate, you should be able to bind the control and assign appropriate event handlers.
I have 2 dropdownlists on a WebForm. Dropdownlist1 controls what should display on DropDownList2.
When the page first loads I pass in a selectedindex of 0 to function to load DropDownList2.
The data loads perfectly.
However when I change the selectedindex on DropdownList1 which causes a postback to recalculate new Dropdownlist2 vales the populating fails. Even though dropdownlist is bound to new datasource that does have data in it.
The data loaded in inatial page load remains in DropDownlist2.
EnableViewState is = true on Dropdownlist2 and 1.
Im developing using asp.net 2.0
I have no idea of why this is failing and would be really grateful if anyone could shed some light on it.
Many Thanks
Tony
Why not use the Cascading dropdwn in the AJAX Control Toolkit? http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/CascadingDropDown/CascadingDropDown.aspx
If you don't want to do that, make sure that populating DropDown1 occurs within a postback check. Otherwise, the DropdownList1 will be repopulated and the SelectedIndex set to 0 on every postback.
if (!Page.IsPostBack)
{
//Populate DD1
}
I'm writing an ASP.Net webform with some DropDownList controls on it. Then user changes selected item in one of dropdowns, ASP.Net doesn't seem to handle SelectedIndexChanged event until form is submitted with a 'Submit' button click.
How do I make my dropdowns handle SelectedIndexChanged instantly?
P.S. It's a classic question I have answered too many times, but it seems no one asked it before on stackoverflow.
Setting the AutoPostback property to true will cause it to postback when the selection is changed. Please note that this requires javascript to be enabled.
You need to set the AutoPostBack property of the list to true.
Also, if you're populating the contents of the drop down list from the code behind (getting the contents of the list from a database, for example) - make sure you're not re-binding the data in every postback.
Sometimes people are caught out by binding the drop-down in the page load event without putting it in an If Not IsPostBack. This will cause the event not to fire.
The same is also true of repeaters and ItemCommand events.
if you are populating the dropdown list during page load then each time the page postback it will reload the list thus negating your postback method.
you need to be sure to load the dropdownlist only if (!ispostback)
Set the AutoPostBack property of DropDownList to true.