I have a page I'm working on with a Gridview embedded into a Gridview. The page uses templates to fill itself out, including the edittemplate for rows. When the row is in edit mode, 3 of the cells contain dropdownlists.
I'm trying to filter these dropdownlists to prevent conflicts. The problem is that when the page autoposts back, the row is no longer in edit mode. Is it possible to persist edit mode on that row through a postback and apply the filter I need to?
The GridView should be in edit mode, even after the postback. Maybe you are forcing a DataBind in Page_Load or some other event.
Related
A page has a gridview bound to a sqldatasource. I don't allow edits in the gridview. Most of it's columns are template fields with label controls. a formview control on the same page shows the data for the currently selected gridview row. Updates are made to the formview control. I want the gridview to reflect the updated data after it has been saved. A simple gv.DataBind() works but the data update can be involved in the gridview's sort, so if I call gv.DataBind() the updated row in gv may end up on some distant page of the grid. I would prefer that the gridview simply update any changed data in the already selected row.
What I've done so far is to have the sub that update the formview also change the text values of the labels on the selected gv row. That seems to work but does not persist. I see the changes in the gv cells, but as soon as I select another row in the gridview, the modified cells in the previously edited row go blank, for some reason.
What's a good way to do this?
Get the current page of the gridview (.PageIndex), do a DataBind(), then (re)set the page.
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
I have created a GridView whose columns are dynamically created based on my data source. I have implemented these columns by using the approach described here.Those columns display properly on the initial load. However, I need to implement commanding so that a user can edit / delete a row in the GridView.
At this point, I have implemented commanding as I would with a normal GridView. I have a TemplateField with an ItemTemplate that has LinkButton elements for edit and delete. The CommandName for each LinkButton is set to either Edit or Delete respectively.
Oddly, when a user clicks either the Edit or Delete link, the data in the GridView disappears. However, I have verified that I am in fact re-binding the data when one of these LinkButton elements is selected.
Can anyone provide some suggestions as to what the cause could be?
Thank you!
Here are good examples. You can figure out postback issue.
http://quickstarts.asp.net/QuickStartV20/aspnet/
I have a RadGrid bound to a LinqDataSource. The grid has auto generated Edit and Delete columns. It displays a simple table without any hierarchical organization.
I am taking the following steps.
Populate a RadGrid using a LinqDataSource
Click Edit on the last row of the grid
From another control on the page, update the linqdatasource and call rebind on the grid
The grid loses track of the current editing item, and opens a different item in edit mode
Please help.
If you rebind the datasource, everything will be reset. You will need to keep track of the current 'edit' item, and 're-activate' it after your rebound the datasource.
Make sure that:
All binding occcurs in the OnInit event (or after the button click is handled)
Viewstate is not disabled for the grid
Using .NET 1.1, I have a DataGrid that contains three columns for each row.
Row one has a label with some text.
Row three will always have two radio buttons and two checkboxes and those are in the HTML side of the page.
Row two will have dynamically generated controls (just textboxes for now) and there can be 1 or more per row. These will be used for user input.
There is a button on the page and when the user clicks the button I need to update the DataGrid’s source (my DataTable) with the new values from the user’s input.
The issue is the DataGrid seems to be losing the dynamically generated controls on PostBack. I can loop through each Item in the DataGrid and I can access the radio buttons and the checkboxes, but the textboxes aren’t there.
Any ideas?
Remember: every time a postback occurs you are working with a new instance of your page class. Dynamic controls added to the page during a previous postback went to the garbage collector as soon as the page for that postback rendered to the browser, along with the rest of that page instance. You need to re-create your dynamic controls on every postback.
you have to regenerate the controls. You should be able to get their values from the http request object