473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Gridview mode not changing back to Readonly after Update

Hello All,

I am having Trouble with a Gridview control In my asp.net/C# application. It contains Some boundFields and one checkbox field. My gridview allows Editing. It succesfully enters edit mode and when i hit update the Datasource updates but the control will not return to readonly mode. I have gone far enough to figure out the problem is caused by the Checkbox field.The checkbox works and passes the correct true/false value to the datasource but will not bind after update When I Make it readonly and remove that value from my Stored Procedure the Gridview control works normal. Please help.
Aug 19 '09 #1
15 15771
Frinavale
9,735 Expert Mod 8TB
I don't understand what you're doing.

You have a GridView that has a checkbox field.
You Edit a record in the Grid view and update the database.

Now what what are you doing??

What is the problem?
Aug 19 '09 #2
Usually when you have a Gridview than can be edited you click the edit button and all the editable fields become Textboxes and the Checkbox is Enabled. I change the values and click update but the gridview stays in Edit mode instead of canging back to Readonly and displaying the new results. If i hit cancel the Grid changes modes and i see the new values. Usually the gridview returns to readonly after update's. I figured out this problem is caused by the Checkbox field . Once i remove this field from my gridview it works (changes modes back and forth) Is there an alternative to the Checkbox that will return true/false?
Aug 19 '09 #3
Frinavale
9,735 Expert Mod 8TB
Once you're finished updating have you tried setting the GridView's EditIndex property to -1?

Like (vb):
Expand|Select|Wrap|Line Numbers
  1.  Private Sub myGridView_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles myGridView.RowUpdated
  2.         myGridView.DataSource = _source
  3.         myGridView.EditIndex = -1
  4.         myGridView.DataBind()
  5. End Sub
(C#)
Expand|Select|Wrap|Line Numbers
  1.  Private void myGridView_RowUpdated(Object sender,  System.Web.UI.WebControls.GridViewUpdatedEventArgs e) 
  2. {
  3.         myGridView.DataSource = _source;
  4.         myGridView.EditIndex = -1;
  5.         myGridView.DataBind();
  6. }
Aug 19 '09 #4
Yes I have tried that. Sorry I should have posted. That does not resolve the problem.
Thanks
Aug 19 '09 #5
Frinavale
9,735 Expert Mod 8TB
Please post the ASP code for your GridView and post your C# code for the GridView's Update method.
Aug 19 '09 #6
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="gvModules" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSourceModulesManage"
  2.  EmptyDataText="No Modules" SkinID="GridViewSmall" Visible="False" DataKeyNames="ModuleId" onrowupdated="gvModules_RowUpdated">
  3.                     <Columns>
  4.                         <asp:CommandField ShowDeleteButton="True" ShowSelectButton="True" ButtonType="Button" />
  5.                         <asp:BoundField DataField="Number" HeaderText="Number" SortExpression="Number" />
  6.                         <asp:BoundField DataField="MODName" HeaderText="MODName" ReadOnly="True" SortExpression="MODName" />
  7.                         <asp:BoundField DataField="ModuleSubType" HeaderText="ModuleSubType" ReadOnly="True"
  8.                             SortExpression="ModuleSubType" />
  9.                         <asp:BoundField DataField="ModelName" HeaderText="ModelName" ReadOnly="True" SortExpression="ModelName" />
  10.                         <asp:BoundField DataField="TargetParticipantUseDays" HeaderText="TargetParticipantUseDays"
  11.                             SortExpression="TargetParticipantUseDays" />
  12.                         <asp:CheckBoxField DataField="NeedsParticipantCompliance" HeaderText="NeedsParticipantCompliance"
  13.                              SortExpression="NeedsParticipantCompliance" />
  14.                         <asp:BoundField DataField="AcceptableWeekDays" HeaderText="AcceptableWeekDays" 
  15.                             SortExpression="AcceptableWeekDays" />
  16.                         <asp:BoundField DataField="AcceptableWeekendDays" HeaderText="AcceptableWeekendDays"
  17.                             SortExpression="AcceptableWeekendDays" />
  18.                         <asp:BoundField DataField="AcceptableHours" HeaderText="AcceptableHours"
  19.                             SortExpression="AcceptableHours" />
  20.                     </Columns>
  21.  </asp:GridView>
I am using SqlDataSource and do not have C# code for update. The onrowupdated code is exactly like to code you posted earlier.
Aug 19 '09 #7
Frinavale
9,735 Expert Mod 8TB
...then where are you setting the GridView's EditIndex = -1?
Aug 19 '09 #8
I set EditIndex to -1 in the Properties window in design mode.
Aug 19 '09 #9
Frinavale
9,735 Expert Mod 8TB
Try implementing a method that handles the GridView's RowUpdated event.
In that method set the EditIndex to -1.
Aug 19 '09 #10
As i mentioned earlier i am using the OnRowUpdated Code like you posted earlier in the OnRowUpdated Event Handler and settint the EditIndex to -1 and Calling the Gridview.DataBind() Method.
Aug 19 '09 #11
Frinavale
9,735 Expert Mod 8TB
Please post that code then :)
Aug 19 '09 #12
Expand|Select|Wrap|Line Numbers
  1. protected void gvModules_RowUpdated(object sender, GridViewUpdatedEventArgs e)
  2.     {
  3.         gvModules.DataSourceID = "SqlDataSourceModulesManage";
  4.         gvModules.EditIndex = -1;
  5.         gvModules.DataBind();
  6.  
  7.     }
Aug 19 '09 #13
Frinavale
9,735 Expert Mod 8TB
Hi stefbek97,

Something in your question is not adding up.

I took your GridView, created an ObjectDataSource that matched the Fields that the GridView was displaying and bound the GridView to it so that I can see what you're "seeing".

What I discovered is that you only have a Select and a Delete Button.

There is no control in the GridView that you posted used for "Updating".

So how can you be having a problem with the GridView Mode change after an "Update" occurs.

Your question doesn't make any sense.
Aug 27 '09 #14
Hello Frinavale,

I understand your concern. I tried to delete and create the gridview over and over to see if there are any errors I made. I changed it from Template fields to boundFields. From CommandField to Buttons "Edit","Update","Delete" with matching Command Name's. My fault i submitted the code and did not verify it. If you and the ShowEditButton="true" please let me know if you can see what i am seeing.
Aug 27 '09 #15
Frinavale
9,735 Expert Mod 8TB
Please post your current version of the ASP code for your GridView and I will try to understand your problem again based on your most current version.
Aug 27 '09 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
1
by: Raja | last post by:
Hi Everybody Just playing with ObjectDataSource and noticed the following. I have a Gridview which binds to a ObjectDataSource. ObjectDataSource gets data from a typed dataset created with VWD. In...
0
by: sach | last post by:
Hi, I am trying to update my gridview using updatestatement..(vs.net 2005) the data gets displayed and after changing it, when i clicked update,nothing happens..it just stays the same..and no...
2
by: sck10 | last post by:
Hello, I have a web page that has a GridView and a FormView, each in its own panel. The GridView shows a list of records in a database. When a row in the GridView is selected the FormView...
0
by: landesjoe | last post by:
Hi, here's my problem in short: Text boxes in gridview don't seem to hold their value if the column's .Visible property is changed back and forth. I've got a form with a gridview populated from...
1
by: Evan M. | last post by:
Here's my GridView and my SqlDataSource <asp:GridView ID="ContactHistoryGrid" runat="server" AutoGenerateColumns="False" DataSourceID="ContactHistoryDS" DataKeyNames="JobHistoryID"...
1
by: savajx1 | last post by:
I need to dynamically create a set of bound fields contained in a GridView control. I also have a single static CommandField that I can declare in the Columns <tagof the GridView control. I have...
4
by: =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?= | last post by:
I setup a simple gridview as a utility just to do some updates, nothing fancy just wanted easy UI to make updates. When I select ‘Edit’, I get the fields I want to edit. I edit them and click...
3
by: pvong | last post by:
VB.NET How do you change a gridview from Update mode to normal mode? I'm usually dealing for Formviews and there is a ChangeMode option but I don't see one for Gridviews.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.