I have a gridview where I am using the update. I have converted the label into a templatefield and added a dropdownlist which is getting polulated in the Rowdatabound event. When I test the update i get an error
Cannot insert the value NULL into column 'StartTime', table 'HTC.dbo.EventDates'; column does not allow nulls. UPDATE fails.The statement has been terminated. so I am ussuming its still trying to update from the label rather than using the dropdownlist. here is my code:
I have added a Command Field in a Gridview Dynamically. And I have added the OnClick Attribute in the RowDataBound event
and ProceedAction() function have confirmation message. When i click the Delete button, the confirmation message is shown. But the Row Command is not fired (even if i click Ok/ cancel in the confirmation message).
This is my Grid view source basically i want as soon as i click on Select Button , the corrsponding Row Data get's redirected to another Page with the Data I know how to redirect to another page with query string only thing is that where and how i can store the data my .cs source
i have a grid with template feild with two button's Accept and Deny and Command Name="update" and command argument ="Accept" and command argument2="Deny" now the problem is everytime when i click any Button it gives me first row data see my source
I am trying to use an Update Command within my GridView. I need to find the "FindControl" for the Edit Command textboxes.
Ie. When the user clicks the Edit button, the row is populated with dropdown boxes, textboxes, etc for editting. Then when the user clicks on Update (button) and the GridView1_RowCommand function is activated with 'if (e.CommandName == "Update")' statement with my FindControl. etc. and my sql UPDATE command statements are used. How do I convert my FooterRow info to my Edit FINDCONTROL info?
I have a Modified Date and Modified By column in my gridview and I want them to be updated with the current date and current user any time a user updates the row.
I converted my columns to template fields and the textboxes in the edititemtemplate are bound to my sql data columns "ModifiedDate" and "ModifiedBy"
Then I added the attached code in my RowUpdating event.
When I test the code and click the Update link on my gridview I don't get an error but the values don't update either. I put a breakpoint on the code and when I hover over "ModifiedDateLabel.Text" I see the old value of the field so I know I'm accessing the control correctly.
The original Item Template was Enabled ="false" I changed this so that you did not have to set the row to a state of edit in order to just select a row. I enabled it so that you could "select" any row with out putting it in a state of edit. the only value changing is if its selected or not. What i am trying to do is use the Data Source Update method to update the bit in the database based on the check box. Currently Update() returns 0. I believe this is because the row/feild is not marked as changed so the Data Source does not see it as something that needs to be updated.
What I am hoping for out of this is post is a way that the rows whom check value has changed to be marked as changed/edited so that the data source will update the database with the values of the check boxes. If all rows are updated this is acceptable as well. I know this is a super simple solution but i have been out of the .NET for a little bit.
I have a asp.net gridview control on my page with several fields and a couple of command fields. However, the update command is giving me problems.
Here is what works. The update command works provided I put straight text into the textboxes that appear. I even have one field that contains a dropdown list which works fine.
Here's the problem. I have two fields that need to access their value programmatically. These fields will reflect the current datetime and the current loggedin user from active directory. I have already created public strings in the C# code.
When I run the edit command on the asp form the grid uses one "DataKeyNames" element. With this the grid can update the selectedrow. However, I haven't been able to access it programmatically in the C# code. I can access the selectedrow in the "selectedindexchanged" event but then I am not able to update my fields in the gridview itself. So, part one of my question is how to I access the "DataKeyNames" properties of a gridview control.
if I can't access the "DataKeyName" property perhaps I could set the label nested within the gridview to the "myCurrentUser()" public string. I am inserting my code to hopefully make this clearer.
I have a gridview based on a sqldatasource that has some colums from which two colums showing the data of two fields: field1 and field2. field1 is an ID which should not be updated and therefore it is readonly=true. The sql-query from the sqldatasource is:
SelectCommand="SELECT field1, field2 from anyView"
What I want is, that when a row is updated, then the value from field1 should be copied to field2 The update-query is:
UpdateCommand="UPDATE myTable SET field2=@field2 WHERE field1=@field1"
My idea was, that the @field2 paramter gets the value from the query string out of field1:
But this does not work. Is there an easy way to copy the data from field1 to field2 when updating the row? In addition, is this possible, even if field2 ist not shown in the gridview (i.e. field2 is selected in the query but is not a field in the gridview but should be updated with value of field1).
I have a parent gridview which has a child gridview in the itemsTemplate. Both are binded to different SqlDataSources. I can successfully update and delete rows in the child gridview. After updating in the child gridview, some related data in the parent gridview are not updated automatically. So i have placed ParentGridview.Databind() in the rowupdated event of child gridview. But it doesnt look working.
I have 3 gridviews in one of my web page, each of which will display different data based on the typeid. I have simplified the system structure in the image below(further description will be stated below the image):
As shown in the image above, the web site(presentation layer) will work closely with the Business Logic layer(BLL) and Data Access Layer(DLL). ObjectDataSource control will be the middle man to select, update, insert and delete the data in the gridviews.
During Select, returned data from the database at DAL will be stored in a datatable and return to BLL and then the website itself.
However, the Update(command button) and Delete(template field) doesn't work,the RowUpdating and RowDeleting event wasn't trigger when I click on the button, but it works if I set the gridviews' datasourceid to the objectdatasource.
Bug: UPDATE command Does NOT Work as Expected on a DataBound GridView This was tested in VS2005 and VS2008
Took a while to figure this out - A simple recurse thru Page Controls Makes UPDATE Not Work as expected.
To Recreate this bug:
A simple Gridview bound to an Objectdatasource on a page with ALLOWEDIT ALLOWDELETE
If one inserts some code (a function call in my example) that just recurses the PAGE controls in either the PAGE_PREINIT, PAGE_INIT, PAGE_INITCOMPLETE events,
Then the UPDATE does not FIRE! and After Pressing UPDATE the GRID does not BIND! You Get A Blank Page - Funny thing tought it's only the UPDATE Functionality that gets affected by this - Everything else works fine including EDIT & DELETE.
If the same function call (recurse thru page controls) is added in the PAGE_PRELOAD, PAGE_LOAD -- Then the UPDATE starts working again as expected.
BELOW Is SAMPLE Code using the NORTHWIND DB Products Table and a Typed DATASET.XSD - You can use your own datasource for the ObjectDatasource - (Note I took out the Foreingkey constraint in products table from Nortwind for delete to work)
NOTE: One should be able to just cut and paste the function PAGECONTROLS_RECURSETEST on any working form that has a bound Gridview with Update functionality and you should be able recreate the bug that way by calling the function from the different page_events
I have detailsview with a SQLDataSource to 1 table (City) and am referencing another table (Unit) for one if it's fields.
I changed the Unit Code (City Table) field into a template field and am using a dropdownlist item to reference the Unit Name from the (Unit Table) with the CityTable.Unit Code = UnitTable.Unit Code. However when I go into the update and change the dropdownlist item to another Unit Name it is keeping the original Unit Code value or it might even be selecting the first value from the dropdownlist item.