ASP.NET - Can't save changes on GridView because of button Postback - c#

I have a GridView, and buttons that do actions (Edit, Save, etc). The GridView is created dynamically. Once I press Edit button, I add textbox (controls) on every cell of the GridView, with their respective text value, so it can be edited.
The problem comes when I click Save button, because when the method starts, it seems like there isn't any textbox in the gridview... so that makes me think if it's because some autopostback stuff when the Save button it's clicked.
Any thoughts about solving that?
EDIT: Clarifying what I want:
1) I got a gridview with data,
2) I put the data of each cell from each row into textboxes,
3) I put those textboxes in the gridview,
4) I do change data in those textboxes,
5) I can't save that data because when I click the Save button, the data on the textboxes deletes itself

You can't avoid postbacks, ASP.NET works with them.
When you click the save button, the page does postback and the Load event fires. In that event, you have to rebuild the page as before you clicked Save (put the textboxes).
If you don't do it, the textboxes aren't there no more and no text can be saved.
Edit: gives unique names to your textboxes, it seems non-sense, but ASP.NET need to hooks on names

Related

Telerik RadGridView row in edit mode is not committed on lost focus

I'm using Telerik's RadGridView in an MVVM app. In this particular gridview users can add rows and edit them. There's also a separate save button to save the items in the RadGridView.
The problem that I'm experiencing is that when the user inserts a new row, but doesn't press ENTER or ESC to cancel or commit, then clicks on the Save button, the bound collection is in a half-baked state. My preferred behavior would be for the gridview to commit the row edit whenever the user clicks anywhere outside of the row being edited. Is that possible?
Turns out it's a simple line of code that can solve this. I eventually was able to solve this myself by placing the following in the event that is triggered when clicking the save button:
gridview.CommitRowEdit(gridview.RowInEditMode);
It takes the current row that's being edited and commits it.

c# pass parameters from a previous action

I'm writing an application that will have a datagridview control and 4 textboxes.
One requirement for the application is that when the user double clicks a row in the datagrid, the 4 textboxes fill with the corresponding textboxes with the data -> this is already done and working. Once the user has edited the field and clicks OK, they will be saved on the datagridview.
On the other hand, if the user clicks a button called "Add Register", the same buttons will be enabled and once they click OK a new register with the data in the textboxes will be created.
The thing is that I don't know how and I have not found any information about knowing if I should edit a row (and which one) or add a new one when OK is clicked.
In other words: how can I know if I'm coming from an "edit" request or an "Add register" request when the user presses "OK"?
Thanks!
Welcome to StackOverflow.
The simplest way to achieve this is to have a boolean field on your form, e.g. bool isEdit. When the user double clicks a line in the DataGridView (a handler for which you say you have working), then set the field to true. Within the Add register button handler, set the field to false.
Now within your OK handler, you simply examine the value of the isEdit field to know, if you are adding or editing!
I have done a lot (a very great lot!) of such DataGridView forms. Personally I do not like to combine the form with data entry. I prefer to leave my DataGridView form as totally read-only, and then when the user clicks edit or add buttons, I display a separate modal form to handle the data entry. On saving from the modal form, I refresh the grid.
HTH

gridview in bootstrap modal popup issue

I used bootstrap modal popup and in that there is need to implement a gridview.
Using update panel,I added gridview and databinding is working properly.
In gridview row, there is a textbox where user can modify the existing values and update with a save button outside the gridview.
But when I fire the Save button command at server side, I am not getting the updated values instead I am getting old values by looping gridview rows controls.
How to get the updated values of from textbox in gridview inside bootstrap modal popup? I have used update panel also.
Please suggest.
In save button event, make sure that you are refreshing the gridview content adding databind() once you have saved the new values
YourGridView.DataSource = TheSource;
YourGridView.DataBind();
after hitting the update and fetching back the updated values you should register back the modal popup from c# at the end of the same event
ScriptManager.RegisterStartupScript(this,this.GetType(),"Pop", "openModal();", true);``
Customize the script according to your need

ASP.NET Postback clears all data in input fields

My ASP.NET page has a few text boxes and drop down boxes. When i change the selection on the drop down boxes or click any button all data available in those fields will be lost. However if i log-in to my page and just refresh it before clicking any buttons everything works as expected. It seems just like the first post back clears everything. Any ideas why it would behave like that?

Button in the Header Template of Repeater

I have an ASP.NET repeater which contains grid view and a panel which contains save button.
the repeater displays grid and save button for each employee..
if there are 5 employees then 5 grids and 5 save button will be displayed.
Now i want to move the save button to Header.. in that case i'll have only one save button for all the grids..
if any grid is modified and i click the Save button, how can we know which grid is edited.
pls help.
If the grids don't post back, i'm not sure it's possible to know which grid was edited. You could add an hidden field to the page (asp:HiddenField) and modify the value using javascript and then check the hidden value when the save button is pressed. Also, why do you have a save button? The gridview has full support for CRUD (Create/Read/Update/Delete) operations.
i think you can use "for each" to loop throw all items in the repeater
and you can check if there is any change in the item then save it if not then leave it and move to the next item.

Categories