C# Update fields belonging to the Id in the query string - c#

I m a newbie to C# and Ive got this doubt please help.
I have these 2 webpages lets call them pageA and pageB .PageA has got a table(used DataGrid) displaying all the fields of a table in sql server ,it has got an additional edit column which displays a link to PageB, the url for pageB has got a query string which contains the ID of the product that is to be updated .In PageB i have got an update form. The form fields of which is already filled (i.e im retrieving data using the ID from the query string using "select").This pageB has got a button which is supposed to update the fields that were edited in this page and store them back to the server .
In pageB :the Page_Load() is where i save the ID to a variable (VarID) and i call the method fill_data_fields() which does the "select" and fills the fields .I ve also got the update_click() which is called when i click the button on pageB it is in this method I ve written the code to update the fields in database .
The PROBLEM is ,that the method update_click() is never called when i click the button.

Any chance that you're adding the button programmatically rather than defining it in the asmx markup? ASP.Net is horrible with dealing with that issue. Also make sure you've wired your update_Click() button correctly in the asmx markup as well. Remember, C# is case sensitive!

Related

Inserting Data into SQL database table from multiple aspx web pages

I am currently have an asp.net web site through visual studio that contains three .aspx pages. Each .aspx page has simple label and text box fields in it. There is a button in each web aspx page also that redirects to the second and third page as well as a submit button at the end of the third page. Also behind the buttons there is an sql command/ query that Inserts the input from the textboxes into an sql database. I have one table in the database that I want input from all three pages. When I tried to do this the input from the first page correctly stayed in the first row. Then the input from the second page made its own second row and so on... I am also using a INSERT statement for each web aspx page. I have a picture below of what the database looks like... how can I get all the input into one row
With your current configuration you'll need an update statement instead of an insert statement on the subsequent pages.
You could also do something like session variables and just insert after you've collected all the information.
If you want to get it into one row, you need to do one INSERT statement and the rest should be UPDATE statements.
Each and every INSERT statement will create a new row in the database.
When trying to UPDATE a row, make sure you add something like WHERE ID = x, so you only update the one row.

Store GridView to session C#.Net [duplicate]

I have a page for searching when I write my name for example in textbox it will search and display the results in a GridView. I'm using an EntityDataSource with a QueryExtender so I didn't write any code in C#.
The problem is: in the GridView I have a hyperlink when I click it, it will go to another page, ok fine then when I return to the previous page the GridView does not show the results of the search when I was left because of the postback (update panel) it show the whole data from EntityDataSource.
I think I have to use session but I don't know how I can do it, I mean how I can save the GridView in session and how I can retrieve it in page_load.

MVC 4 Submit button in each row of a "grid" - how to?

How can I have a submit button in each row of a "grid", where, when that button is clicked, I can POST three pieces of data in the row to the controller?
Here's the scenario:
A screen shows my system's users in an html table "grid". One link in each row says "Associate Customer". This goes to another screen showing a list of customers that this user can be associated with. Their UserID is in the URL like AssociateCustomer/14
On the second screen, I want to display in an html grid, CustomerID, CustomerName, and a link/button that either:
Says "Associate" if they aren't associated with that customer, or
Says "Disassociate" if they are already associated with that customer
I got that much working, but I don't know the next part: when the user clicks a button on the grid, I need to pass CustomerID, the UserID, and "Associate/Disassociate" to the controller. How can I do that in an MVC way?
Something like:
# Html.ActionLink("Click Me!","Associate","SomeController",new{userId=item.UserID,customerID=item.CustomerID})
You don't have to post the form to do what you are asking (though that would be one way to do it).
Generally you won't post the form in this case.
I would create Associate and Disassociate actions in your controller that accept the parameters you require as querystrings. Then build an ActionLink for each row of your grid that builds that appropriate URL.

Non editable row in GridView

I am creating a web page using C# ASP.NET and Visual Studio 2008. I would like to create a dataentry form on my web page using GridView. Whenever a user may, he/she can edit the record on GridView (I have did this using edit, update, cancel option) but I would like to place another button in GridView named "Close" by which user can make that particular record "Non-editable". After clicking on close button on Gridview that record get locked and no body can edit that record in future.
Can anybody help me?
Maybe you can do that by adding a column to your table in your database. If the close button was clicked in your gridview, update the data in the database and make it closed so that it cannot be edit in your gridview.
Hope this gives you idea.

POST Row Id to a new page for editing

Please help me out here I have about 1 day experience of C# ASP.NET web dev and I am stuck on something really simple. I am much more experienced in PHP and jQuery.
What I need to do:
Create a GridView and display data from MSSQL DB [done]
Add buttons to each row to enable direct editing of values in two columns [done]
Each row represents a list of equipment that the user can edit/save, and I need to add an extra "Edit Details" button to each row [done]
Upon clicking the "Edit Details" button, I need to pass the id of that list to a new page where user can edit and save the list
I have added a HyperLinkField for the row id to be passed on, in Visual Studio I have tried to config it so that the value can be read on the receiving page with Request.Params["xxxx"] but it is not working.
In PHP I would just create a POST <form> with hidden <input> values and obtain the value by $_POST["xxxx"]
However it seems that all this fancy ASP.NET and Visual Studio DataSource pointer/reference and config things are making things more complicated than I wished.
I greatly appreciate any help given, or any resources that will be helpful for me to transfer my skills in PHP over to ASP.NET with C#.
If you are passing it through query string use
string value = Request.QueryString["id"].ToString();;
If you are passing it through post use
string value = Request.Forms["id"].ToString();

Categories