Button in the Header Template of Repeater - c#

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.

Related

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

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

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

Auto adding textbox

I wanna ask for your opinions/ideas about how to automatically add new Textbox when user click on Add button. In my system, there are 2 Textboxes which user need to enter expenses and price respectively. And there's also a ADD button. When they click on it, another two boxes will automatically generate. Before this, I only have 8 Textboxes for expenses and 8 Textboxes for their price. But it looks quite messy for me so i want to make it more tidy. Thank you
You could use a grid and then have a hidden row that has the same input cells as the other rows. When the add button is clicked, have javascript clone the hidden row and then add then show it, and add it to the bottom of the grid.
If a grid isn't right for your UI then do the same thing with just cloning a text box and showing it. It is often easier to just have a single hidden input field with the proper style applied and then clone it, and then remove the display: hidden.
But it looks quite messy for me so i want to make it more tidy.
GridView should be used to make it visibility better and consume space properly.
Assign the DataSource to your GridView
Set the Text boxes in your Footer
When you click the Add Button, Set the Visibility of your Footer "True"
Once user fills the values in Textbox save it and Bind to the GridView.
Repeat Step 4 to iterate the same process next time.

Web application Listview question

In a list view in C# how can I make all the fields in a column editable at once? Right now I have the standard edit button which allows me to update just one line at a time. I want the end user to be able to click a button and allow then to edit the column in its entirety.
Rebind the ListView with all TextBoxes when the user clicks edit.
You would have to manually track if you're in edit mode or not and on postback loop through all the rows retrieving the values from the textboxes and store them.
There is no built-in functionallity for what you're trying to do but it's possible.

How to access value of list box?

I have update panel which gets updated on button click event. Out of the update panel,there is list box. When user clicks on the button which is placed inside update panel, at that time I want to retrieve selected items from the list box, but when I click the button, the selected index of list box is showing zero even if I select any item. I cant understand why it is happening so. Perhaps it is because partial update is taking place. How to tackel with this problem??
When you click the button, your page does a postback to the server on page_load and I think you are binding again. That's why the previous selection cleared. You should take care of the IsPostBack Condition while binding data to the listbox.

Categories