How to persist an ASP:Table with TextBoxes inside cells? - asp.net

I have an ASP.Table whose cells are containing textboxes filled by the user.
When he clicks on a button, I want to store textboxes content into a database but in the onclick event, the table is empty. How can I persist the whole table, and especially the textboxes data ?

Create a name value collection corresponding to the columns and rows of the table. Store each cell value as a part of the name value collection in the DB with the name in the form of r1c1, r1c2, etc.

Related

How to design a gridview or table with datasource having blank first row in which we can search table column in asp.net?

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.

Java FX 8 Tablecell data to Listview selected data

I have a Java FX TableView with a column. This column is pre-populated with values from a database. When I click a cell on the table a listview is shown, I can update the table cell and the DB by selecting the values from the list.
Before the listview shows up, I set the selected value of the list to match the existing table cell's value by the following
listView.getSelectionModel().select(this.getItem());
when the list view opens the selected item corresponds to the cell value of the table.
I have a onchangelistener attached to the listview's selectedItemProperty.
From this list view if I choose a new value, When the selection changes the DB gets updated and the table cell gets updated with the new value.
If there is a problem with the database update, the listview's selected ItemProperty still retains the newly selected value.
I have tried resetting it using
listView.getSelectionModel().select(this.getItem());
but this doesn't reset the selectedItemProperty value.
Hence if you click the same cell once again, the list is having the previously selected value highlighted (i.e the value which was not updated due to a DB failure) the table cell and the selected value in the listview are different.
How do I overcome this ?

GridView record update help needed

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.

Usage of DataKeyNames in an ASP.NET GridView?

In which cases should I use a GridView's property DataKeyNames?
Why are multiple columns/fields allowed here?
Gets or sets an array that contains the names of the primary key fields for the items displayed in a GridView control.
GridView.DataKeyNames Property
GridView.DataKeys Property
It keeps the primary key fields or id field of data table, which gridview shows.
According to MSDN
Gets or sets an array that contains
the names of the primary key fields
for the items displayed in a GridView
control.

GridView Initial Editing mode?

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.

Resources