how to add button click event in grid view in asp.net - c#

1)
I had a GridView and I added a button in every row. I want to know how to select one row by clicking that button according to that row. And I should insert that record into an other table.
Eg:- I have two tables (Course and Wish List)
I bind the course details into the GridView and add a button as "ADD TO WISHLIST" at last column.
I want to add that record into the wishlist table clicking the button.
enter image description here
2)
My second need is: I have added an image in a database table as binary value successfully. But now I can't load this data. How can I do that?

Related

how to insert a new record from asp.net grid view's header

I have searched but I got only this:
https://www.asp.net/web-forms/overview/data-access/enhancing-the-gridview/inserting-a-new-record-from-the-gridview-s-footer-cs
Here footer template is used I want same but data should be inserted from header also the grid view should have a column name as its first row and then textbox as the second row and insert button for every row of the textbox.
Opposite of the solution provided in link.

after updating dynamic gridview in asp.net it is showing multiple values in each row why

here i am going to update multiple values at a time by using single button click
On clicking update button for gridview it is showing multiples values for each and every column
After refreshing the page it is showing normal data
For example if i am inserting 1 in 1st column, 2 in 2nd column after updating gridview it is showing 1,1 2,2 like that
Because your gridview has autogeneratecolumn = true. change to false.
Or if you want custom header name do this steps:
in gridview property (Design part) click edit columns -> your boundfield -> under its property, you can see the "DataField", set your field name of your database. You can see now the data of your records from your database. also you can set header name.

Save a editable Grid View on a single save button ASP.NET 2.0

I have an editable gridview. The rows are editable. I can save each row by clicking corresponding save button for each row.
But the problem is I can not have save button/Link for each row. there will be a single "save" button below the grid. After changing values on the grid , by clicking on save all the changed rows will be updated in DB.
Have a look at this tutorial: GridView Bulk Editing

Inserting New Row in existing GridView from Footer(Contains Dropdowns and + button)

I have a case in which I'm showing gridview which is binded with the datasource using linq.
in footerrow of GridView I have an option to select values from 2 dropdowns and click add button an on add button I'm adding data in DB and showing data from DB.
What actually i need is that on add button it must be added to the gridview. and if gridviewrowbound is empty the user select from footer and add.
I have another UPDATE Button,on update I want to save changes to DB
I tried DataTable but couldn't do it.

Add data to gridview and then retrieve it and add to a database

I am doing an academic project. For that need help in a form.. in billing form.
First of all I will show you my two tables connected to this operation.. I can't add hyperlinks and photos because I am a new user.. so.. pls add http:// infront of image links below..
Items table:
Sales table:
And here's my demo layout of my form
In the form you can see a dropdowlist. In that list I bound the item_code from item table ... when load form all items will load in that dropdownlist..
Next is a textbox... it is to enter our quantity of item we purchased... that we want to enter at that time...
Then you can see a button called ADD TO DATA GRID. When the user clicks on it, I want to add a row to the gridview that contains item_code which we selected before from the dropdowlist and quantity which we entered in the textbox..
And I want to add 3 more columns to the gridview, size, item_name, tax.. these items I want to fetch from the items table using
select size, item_name, tax
from items
where item_code like '" + dropdownlist.selecteditem + "';"
I think you got it what I said... and I think it's clear what the Delete button should do.. when I click on it, I want to delete that specific row...
Next you can see a label.. total.. there want to add the price*quantity which we adding to grid.. means if I added a item and that have price 50 and quantity 2.. the total will be 100 then I added another item have price 20 and quantity 2 then add 40 (20*2) to total then total will be 140(old 100 + 40)..like that...
And finally you can see a button called final submit.. when pressing this button... want to add the the one by one row to sales table from gridview and some data want to fetch from the items table.. means in gridview only have item_code,name,price,size and tax.. when click on final submit button want to add whole 9 fields of items table to the sales table, one by one have in gridview.
Use a DataTable and link it to DataGridView, fetch database data into DataTable and update any changes made to GridView to DataTable and then Update to database using that DataTable
GridView.DataSource=DataTable;
GridView.BindData();
After you made change to GridView update them to this DataTable using a BindingSource or just use for loop and then update to database

Categories

Resources