I have a Master Page which contains a Dropdown, based on the Drop down selection I change the language of the entire site. Now, in one of the child pages I am using a repeater and binding some data to it. I am also using the ItemDataBound event of the repeater as well (I require a tooltip for one of the cells). I am trying to figure out a way when the master page Dropdown value is changed I should also fire the ItemDataBound event so that the data is displayed in the correct language. I am guessing it has to do something with playing around certain events. Any ideas or feedback will be appreciated.
ItemDataBound is only fired when data is bound to the control. You would have to rebind the data to the repeater in order for its ItemDataBound events to fire again.
Your other option is to write additional code to loop through all of the items in your repeater and perform the actions you usually perform in ItemDataBound.
Related
I'm creating a simple custom pager for repeater (or anything else, it doesn't actually matter because all I want from it is current page number). Pager has 3 public properties: PageSize, MaxResults and PageIndex.
First is set in markup, second is set on the page in Page_Load or EventHandlers when various buttons are clicked and repeater is databinding again. Third is decided by user when clicking on page numbers.
Page numbers are dynamically created LinkButtons with OnCommand set to method that launches my pager's OnPageChanged event to inform webpage that it need to reload data.
The problem is that in order to create correct number of page linkbuttons I need to know MaxResults. I will know it not sooner than in Page_Load and most probably even later. But as far as I know if I want my linkbuttons to fire events they need to be created before Page_Load when I don't know MaxResults...
Now I'm creating linkbuttons in Page_PreRender and event's don't launch. What is the solution for this? It looks like GridView's built in pager is also done with LinkButtons and it also can't know count of data before databinding but the events are firing.
I have a gridview inside a User Control which is being filled with data from a data source dynamically. One of the things I need to support is switching a non-data-bounded column from checkbox column to radiobutton column dybamically.
everything's cool when I create the columns for display, but when I try to add an event to the CheckChanged (or Click) of the columns, the events doesn't fire - Not at AsyncPostBack and not at full postback. Moreover, the AutoPostBack is set to true and the checkboxes and radiobuttons do fire the postback, but not their events.
I don't think it's relevant, but the loaded usercontrol is in a ModalPopUpExtender from AjaxToolkit and it is being showed at server side (using a dummy button, and a clickable button ith a server side event on click). Also, all the ModalPopUpExtender controls are inside of an UpdatePanel, and only the clickable button is not.
thanks in advance.
I'm not sure if it'll work using Ajax and ModalPopUpExtender but I think you need to handle it in the OnRowCommand event of grid.
So, the column of the checkboxes should have been added in a static sort of way (declare the column and the checkboxes/radiobuttons in html) - the page would register to the events, or needed to be registered in PreRender of the GridView, after acknowledging that they were added during an Ajax postback... the latter is the best way... but for those who have no time to debug, first way is better. see also:
http://www.codeproject.com/KB/custom-controls/asp-ajax-custom-controls.aspx
I am trying to update controls in the of a ListView control after handling the ItemCommand event.
My ListView displays line items of a purchase order in the as html table rows along with a TextBox to enter a new quantity and a Button to update the quantity. My ListView then displays sub-totals, discounts, and a grand total of the line items above in the as html table rows as well. On initial load, I set the values of the controls in the ListView's in the LayoutCreated event handler.
When a new quantity is entered and the button to update is clicked, I handled the event in the ItemCommand event handler. I update the quantity of the specific line item. I then re-bind my ListView to the underlying collection and call DataBind(). The problem is, LayoutCreated is not fired this time around, only on initial load.
My work around is to just pull those controls out of the and address them as static controls, but I like having them inside because my table markup can be fully contained in the and my can show cleanly without having to juggle the static controls' display properties.
Is what I am asking possible? Thank you for any help you can provide.
I'd reccomend handling the DataBound event of the ListView (instead of the LayoutCreated event), and setting the values there. That will get called everytime you re-bind the ListView, as well as when it loads for the first time, which (from your description) is what you want to do.
On my asp.net page, I have several DropDownLists.
I also have a Repeater.
In the ItemDataBound event I want to get the value of these DropDownLists, to change the data in the Repeater. The SelectedValue of these DropDownLists is empty.
But after the ItemDataBound, the Page_Load is executed. There I can get the value of these DropDownLists.
Is there a solution to get the value when the ItemDataBound is executed.
thanks!
Filip
You need to data-bind these drop-down lists in the Page.Load event.
There're a lot of web controls that get their state or other details during load life-cycle (I had these kind of problems long time ago).
NOTE: When I say "State" I'm not talking about ViewState.
And why don't you do that data-bind after the load event?
Can you get the drop down lists' selected values in the page PreInit event? If so, store them in view state and retrieve them from view state during the repeater's item data bound event.
If that doesn't work, try adding a selected index changed event to each drop down. When the drop downs change, set a view state variable that you can retrieve during the repeater's item data bound event. If you have values to which you are setting the drop downs during page load, such as when reading from a database, use those values to directly set the appropriate view state variables.
Ok, i have a gridview and on page load, i dynamically add a column to it that contains a link control. this link control has a onclick event associated with it so that when its clicked, i want to do some processing. Now I have noticed that if I just bind the grid the first time (i.e. if(!IsPostBack) and have enableviewstate for the grid to be true, clicking the link in that column, doesnt trigger the onclick event. But if I bind the grid on every postback, everything seems to be working..does anyone know the reasoning behind it?
It happens because you're dynamically adding the column, so on every postback the column has to be created. What you may want to do is to look at Creating a Custom Column.
May be creating the row Id solves your problem. Check out this link and the post marked as answer.
http://forums.asp.net/p/1471128/3408069.aspx#3408069
Regards
Vinay