Using built in 'edit' and 'delete' buttons in gridview. ASP.NET C# - c#

I have a workout database where some data from most of the tables is pulled and outputted to a gridview. I have taken a screenshot of my gridview output for reference.
http://postimage.org/image/vncyu4oet/
As you see I have the 'edit' and 'delete' buttons on the table. There are two main things that I want to know how to do, and I have probed all over the web and haven't been able to find a solution.
1) When I click 'edit' I want only one row to be affected (which I have working), and I also want only certain cells to have the ability to be edited (namely the Date, Workout Name, Weight, and Repetitions), while the other ones can't be. Is there a way to restrict that? Lastly, once the user inputs data, how do I then update the multiple tables all at once? I have seen code on how to edit just one table, but my gridview pulls data from multiple tables like I said.
2) When clicking 'delete' I just want that row to be affected, not all the other rows that have a matching date, matching workout name, etc.
Any help is appreciated!!

Related

Why does my GridView control in c# aspnet display an old table below the new table?

The objective i'm trying to achieve is to display filtered data in the same gridcontrol.
So what I do is e.g A-DROPDOWN clicked, display XDATA in GRIDVIEW1. Then FilterA selected, this filter calls the "ADROPDOWN" clicked event again and then checks the appropriate filter then passes the appropriate sql query, then displays "YDATA" in GRIDVIEW1.
Now when I select B-DROPDOWN, ZDATA is displayed however below it is the YDATA. If I select C-DROPDOWN, VDATA is displayed howver below it is still the YDATA.
If I selected A-DROPDOWN then XDATA would be displayed then if I would selected B-DROPDOWN without selecting any of the filters, WDATA would be displayed cleanly in GRIDVIEW1 without any data below or above it. Would appreciate if anyone has any suggestions. Cannot show my code because its 20000 lines.
Would like to add. The alphabets assigned to the dropdowns and data represents the different datasets.
SOLVED !!!
Incase it is of help to someone. my update panel in my front end was only updating the gridview, not the table where the grid view was located . I simple made it so that my entire table where the gridview was located was updating. Many thanks.

How do i add dynamic dropdownlist to a table created by codebehind

I want to build a web page using asp c# which has 4 Cells Labeled "MachineName (Label), Owner (Dropdownlist), Release(dropdownlist with default values of Yes/No), Comments (Textbox)".
Content of the table is loaded from SQLServerDB.
1. In each cell it shows records for one Machine.
2. Owner is dropdownlist, which consist names list from SQLTable (ADuser) of 500 users. But by default it show the current owner of this machine fetched from SQLServer Table (inventory) from which we are getting machine names.
3. Release is simple dropdownlist with default values "Yes/No".
4. Comments is just Textbox.
5. Update/Submit button to update the record column.
I am trying to put all these in simple line. Machine name is static which cannot be edited, Dropdown, Release and comments should be editable and finally with Submit/link button at the end of the Columns to update the particular record only.
I tried by creating Grid, but in grid we get DELETE/EDIT/UPDATE button options.
Tried by creating Placeholder and generating and filling data using htmlappend option. But this way, i am not able to add/bind dropdownlist dynamically.
Any help is appreciated.

Is two data sources for a DataGridView.ComboBoxColumn possible?

I have a DataGridView with several TextBoxColumns and one ComboBox column called 'combo' that holds the client type. The problem is that I'd like to show both the currently selected client-type value along with the dropdown client-type list to validate future changes by the user. In SQL Server, I have a DB with two table columns, 'client_type_dropdown.name' and 'clients.client_type'. The 'client_type_dropdown.name' column is a validation list. The 'clients.client_type' column contains the current client type for clients in the database. Is there a way to show in 'combo' both 'client_type_dropdown.name' and 'clients.client_type' , i.e., one source for the ComboBoxColumn dropdown and a different source for the textbox part of 'combo'? Or do I need to have two columns in my grid?
I appreciate your help.
I'm using a third party grid, but I usually handle this by setting the combo drop down style to DropDown instead of DropDownList. This will allow your original database value to display, even if it isn't in the list.
This also allows free typing of values into the combo field, so the trick after that is to validate the user input to make sure it matches a value in the list before you allow them to save updated values. You could play around with the LimitToList property of the combo to possibly save you doing the validation manually, but with most controls I have worked with it will give you more grief than help.

Binding gridview from sql table but this binding not for particular table it keeps on changing depending on user input

I have a table called TableExplorer which contains other table's names and their respective column names.
For example: table Customer may have 5 columns but in TableExplorer I may mention only 2 column names out of 5.
User send me the table name in query string, my job is to find that table name whether it is present or not in TableExplorer which I mentioned initially. If the user mentioned table is present then I should bind that table to a gridview and that gridview should have functionality like edit, delete, update. Finally any operation like edit, delete or update made by user should reflect in the respective table as mentioned by the user.
Database used : SQL Server 2008 R2
Programming language : C#, ASP.NET
Thanks in advance for helping.
Are you using WebForms? I'm far from being a WebForms expert but this is what I'd do:
You create different pages with GridView control, one for each table that you might want to bind, eg. Customer table. You create the CRUD operation for this GridView, Insert, Update, Delete. You create parameters for all the columns that the user might need, some of them could be invisible.
The user goes to his selection page, he choses a table and a list of columns and press Submit his request. Whenever you receive the query string you do 2 things:
Identify what table your user is asking and load the right page, if available. Maybe you can load only the specific GridView control in a specific using Ajax. Or maybe you can simple load another page.
Get the list of columns that the user wants to see in his grid from the querystring. Before showing the grid to him you keep these columns visible and hide/remove from the gridview every other column. You must pass this parameter to your insert/update methods as well.
I think this is a good solution to start, assuming you don't have a list of hundreds of tables, I wouldn't try to create something completely dynamic.

How to generate freeform rdlc reports with one page per row

Given a data set containing multiple rows, from within a .NET console application I need to generate a report on a single page for each row, sending those pages directly to the printer.
I am attempting to use Microsoft Report for this by attaching it to a data set and placing TextBoxes where I wish. Generating the report and sending it to the printer are not a problem. Unfortunately, the data only seems to be available in aggregates -- First, Sum, Last, Max, etc. I cannot latch the text box to a bare field.
Some poking around here and other sites seems to address this, but only when the data is presented in a table. One post even said without elaboration, "My mistake was using Text Boxes"
Am I using the wrong tool for what I am attempting to accomplish?
I ran into the same problem and managed to solve it. The solution seems a little convoluted to me so don't quote me on the "right" way to do this, but here is what I did:
Make sure you have a Dataset defined for your report.
Add a "Table" control to the report. This seems to be needed in order to iterate the rows in your Dataset.
Delete the header row and two of the default columns from the table so that you are left with a single row with a single column.
Expand the table to the width of your layout and make it as tall as you will need for your "free form" layout.
By default, there is a TextBox inside the table cell. Right-click the empty table cell and choose "delete" to remove that TextBox.
Drag a "Rectangle" control into the empty table cell. It seems to automatically "dock" to the width/height of the table cell.
Now you should be able to drag the fields from your DataSet (TextBoxes, etc) into the Rectangle to produce the desired layout.
Note that I am in the early stages of using this approach so I'm not sure if I am going to hit any walls... but for a basic report that uses TextBoxes and a page break after each "row" it seems to be working ok.
Or you try to use a list.
In the list you can arange textboxes (and other controls) as you want and they will be filled for each record in the recordset.
This work for me. :-)

Categories