I have a table in database.
This table has 10 rows and 4 columns which contains ID( an integer value coming from UI ).
In front end in asp.net application i bind all 10 rows to a Grid-view.Grid-view has 4 column and each column contains a drop-down list.
There is a button called Update on screen.
I want to update database table on clicking on Update button i.e. whatever option is selected in Grid-view should update in database table.
What would be the best approach to do it?
Thanks
Use a codebehind handler to handle the button click, then do a database update based on the values in the Gridview.
Related
I want to design a grid view or table that gets data from database then i want leave first row blank. when user click in the cells of first row and type in, it shows every data that matches.
You can use textBoxes to query your requested data in gridView and use onTextBoxChanged to update the gridView. Instead of increasing the code you also can do it using Table let's say you have 5 columns on the gridView you make table with 5 columns and 2 rows, the first row you put 1 textBox in each cell, in the second column you use colspan property and set it to 5. Then use the event onTextBoxChanged call the SQL command and query the data on textBox then update the gridView.
I am working on old webform asp.net application which uses Repeater.
The Repeater is a set of Name and address textbox fields. I have 3 sets of Name and Address information, basically, 3 sets of records in the object list to bind.
On the UI, I changed/update one of the Name and Address. I noticed in the list, which it iterate or loops through the repeater control
foreach (RepeaterItem item in this.NameAddressRepeaterControl.Items)
I see that an extra recod is added to the items.
Question:
I am used to fixed textboxes. When I update the textbox, I write code to take Exactly what is filled in the textbox and populate the DTO object to pass to the data layer to perform database transaction to update the database records.
When the new updated record is added to the Repeater Control list, I don't know which records is updated and which is the new records.
I am checking out OnItemDataBound and OnItemCommand to see if there is a way to get the old value from one of the field and also record the value of the new value. Is this possible?
The form contains 1 Save button and it will loop through the Repeater.Items to see what Name/Address to extract, but the new and old company exist in this list.
Instead of looping through the RepeaterControl.Items, Is there a way to extract from directly the visible Repeater control? If there are 3 repeater Name/Address control, is there a way to get all the info from each of the 3 sets of Repeater controls? The Repeater wraps around a user control, NameAddressCtrl.
I prefer not to replace the Repeater controls with fixed textboxes.
Any help is greatly appreciated.
Thanks.
I reviewed the code several time and add additional code to keep track what was add and changed in the repeated and only passed the information to be saved to the db. The solution was to write additional code. I did not change anything with the repeater behavior. Thanks for the comments and help.
I am creating a table dynamically.
Now I add some data to the table from Database.
On Every Row of the table I create a button.
Up to this it works fine.
Now when user clicks on that button I want to add a new row to the table just below the button was clicked. I mean I want to insert a new row between the existing rows.
Any Ideas?
If you are using a grid view or data table then apply the commandname property to the button then handle it in the grid view/data table command click method. From there you can determine which row the button is in and then create a new row and insert it below.
If you are creating the table HTML dynamically then it is a bit trickier, I would add HTML comments after each row with the row number and give each button a command argument with the row number too so I could replace the comment text with a new row.
tbl.rows.addAt(Position)
Here Positoion is the variable holding the value where to insert the new row.
when use this code you can insert row between other rows in datatable in vb.net
tbl.Rows.InsertAt(newRow, CurrentRow)
I have a gridview with multiple columns however I only want to update one of these columns in the database. I have set all other columns to read only so that the only editable field is the one I want to edit however when I update this field all others get deleted but I want them to remain the same. How do I accomplish this?
Thanks
Make the gridview fields TemplateFields, you can then access the EditItemTemplate of the fields. In the editItemTemplate, instead of Textbox( by default) you replace the textbox with a Label for the fields for which you don't want the edit facility.
similar question here http://forums.asp.net/t/1099084.aspx/1
When You are updating your data base values you can also update all other values which read only. and one editable column value change each time .
I am writing a web application that is used for tracking and entering some everyday user data... Every day I need to enter some data for multiple users manually...
I will choose the date with the calendar, and for that date I will get DB values assigned for all users on chosen date...If there are some entries in database for that date i will display it in gridview...
Here is the look of gridview for chosen date...
USERS DATA
------------
User1 Data1
User2 Data2
User3 Data3
But, if I choose the date for which there are no entries in DB, I would like to display the gridview containg User names in each row, but I want the second column (DATA field) to be initially editable for ALL rows (the whole second column should contain textboxes for inserting values, not only selected row as in standard editable gridview mode) allowing inserting of wanted values...
I want it to look something like this
USERS DATA
----------------
User1 TextBox
User2 TextBox
User3 TextBox
My idea is to get Users list from DB and create a datatable with first column containg returned user names, and second column empty... This datatable will be datasource for gridview in which I am going to disable editing mode, and in normal (displaying) mode I am going to have TemplateField containg of textboxes bound to that datatable in second column, and labels displaying usernames in first column... When entering all values there will be SAVE button who is calling a method that will read entered values from datatable and save it to database...
Is there a better way to implement this functionality? If Templatefield textboxes are bound to datatable (as gridview datasource) textboxes entered values are going to be accessible from datable object, but Save button click causes postback, and I don't know how to preserve datatable state? Is there a better way to get wanted gridview with whole second column availibe for inserting new values?
Thank you in advance for your help & time!
Try this
http://www.highoncoding.com/Articles/219_GridView_All_Rows_in_Edit_Mode.aspx
http://csharpdotnetfreak.blogspot.com/2009/05/edit-multiple-records-gridview-checkbox.html
I would retrieve the full dataset using a left join in the database, and if there is no entry for a user, that user will be returned with a blank value. Something like this:
select users.user,
isnull(entries.entry,'')
from users
left join entries on users.userid = entries.userid
I think you can override the OnDataBinding (or OnDataBound) method to check and see if the second column is empty, and place the field in edit mode if it is. This way, if some users have entries but some don't, only the users with no entry will be in edit mode. Any user with an entry will be in display mode. There is a sample for this at http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdatabound.aspx.