Connecting Tech Pros Worldwide Help | Site Map

Gridview mode not changing back to Readonly after Update

Member
 
Join Date: Aug 2009
Posts: 36
#1: Aug 19 '09
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.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#2: Aug 19 '09

re: Gridview mode not changing back to Readonly after Update


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?
Member
 
Join Date: Aug 2009
Posts: 36
#3: Aug 19 '09

re: Gridview mode not changing back to Readonly after Update


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?
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#4: Aug 19 '09

re: Gridview mode not changing back to Readonly after Update


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. }
Member
 
Join Date: Aug 2009
Posts: 36
#5: Aug 19 '09

re: Gridview mode not changing back to Readonly after Update


Yes I have tried that. Sorry I should have posted. That does not resolve the problem.
Thanks
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#6: Aug 19 '09

re: Gridview mode not changing back to Readonly after Update


Please post the ASP code for your GridView and post your C# code for the GridView's Update method.
Member
 
Join Date: Aug 2009
Posts: 36
#7: Aug 19 '09

re: Gridview mode not changing back to Readonly after Update


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.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#8: Aug 19 '09

re: Gridview mode not changing back to Readonly after Update


...then where are you setting the GridView's EditIndex = -1?
Member
 
Join Date: Aug 2009
Posts: 36
#9: Aug 19 '09

re: Gridview mode not changing back to Readonly after Update


I set EditIndex to -1 in the Properties window in design mode.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#10: Aug 19 '09

re: Gridview mode not changing back to Readonly after Update


Try implementing a method that handles the GridView's RowUpdated event.
In that method set the EditIndex to -1.
Member
 
Join Date: Aug 2009
Posts: 36
#11: Aug 19 '09

re: Gridview mode not changing back to Readonly after Update


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.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#12: Aug 19 '09

re: Gridview mode not changing back to Readonly after Update


Please post that code then :)
Member
 
Join Date: Aug 2009
Posts: 36
#13: Aug 19 '09

re: Gridview mode not changing back to Readonly after Update


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.     }
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#14: Aug 27 '09

re: Gridview mode not changing back to Readonly after Update


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.
Member
 
Join Date: Aug 2009
Posts: 36
#15: Aug 27 '09

re: Gridview mode not changing back to Readonly after Update


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.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#16: Aug 27 '09

re: Gridview mode not changing back to Readonly after Update


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.
Reply