Solved

GridView RowUpdating can not find edited information

Posted on 2007-03-27
7
428 Views
Last Modified: 2007-12-19
I have the following TemplateField in my GridView:

             <asp:TemplateField HeaderText="Send Email?" SortExpression="SendEmail">
                    <EditItemTemplate>
                        <asp:CheckBox ID="cbEditSendEmail" runat="server" Checked='<%# Bind("SendEmail") %>' />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="cbSendEmail" runat="server" Checked='<%# Bind("SendEmail") %>' Enabled="false" />
                    </ItemTemplate>
                </asp:TemplateField>

I am trying to use the RowUpdating event to pass update parameters to a ObjectDataSource as follows:

    protected void gvAdminRights_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        CheckBox cb = ((CheckBox)(gvAdminRights.Rows[e.RowIndex].FindControl("cbEditSendEmail")));
        odsAdminRights.UpdateParameters["SendEmail"].DefaultValue = cb.Checked.ToString();
    }

The code finds the CheckBox. However, it does not return the updated Checked state. I always get the previous Checked state. So if the CheckBox was checked before I went to edit mode and unchecked it, I am still getting true for cb.Checked.

What am I doing wrong here?
0
Comment
Question by:IUAATech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 11

Expert Comment

by:lijunguo
ID: 18804471
try to  change your asp:CheckBox EnableViewState=false
0
 

Author Comment

by:IUAATech
ID: 18808044
Thanks for the response. Disabling the viewstate of the checkbox didn't fix the problem. This has been driving me nuts. I am sure others are having the same problem. I have spent 2 days on this and haven't been able to come up with a solution.

What do you think is the problem here?

I am binding the gridview to an ObjectDataSource as follows:

        <asp:ObjectDataSource ID="odsAdminRights" runat="server" DeleteMethod="DeleteAdmins"
            SelectMethod="GetAdmins" TypeName="AdminRightsBLL" UpdateMethod="UpdateAdmins"
            OnUpdating="odsAdminRights_Updating">
            <SelectParameters>
                <asp:QueryStringParameter Name="ModuleId" QueryStringField="mod" Type="Int32" />
                <asp:ControlParameter ControlID="dropAdminRightsCriteria" Name="EnvironmentID" PropertyName="SelectedValue"
                    Type="Int32" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="userID" Type="Int32" />
                <asp:Parameter Name="moduleId" Type="Int32" />
                <asp:Parameter Name="environmentId" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="UserId" Type="Int16" />
                <asp:Parameter Name="ModuleId" Type="Int16" />
                <asp:Parameter Name="EnvironmentID" Type="Byte" />
                <asp:Parameter Name="SendEmail" Type="Boolean" />
                <asp:Parameter Name="AssignRequest" Type="Boolean" />
            </UpdateParameters>
        </asp:ObjectDataSource>

and the UpdateAdmins in my BLL is as follows:

    public static bool UpdateAdmins(short UserId, short ModuleId, byte EnvironmentID, bool SendEmail, bool AssignRequest)
    {
        int rowsAffected = 0;

        rowsAffected = QuerysAdapter.UpdateAdmin(UserId, ModuleId, EnvironmentID, SendEmail, AssignRequest);

        return rowsAffected == 1;
    }
0
 
LVL 3

Expert Comment

by:emailrobertwalker
ID: 18811963
Have you tried the "RowUpdated" instead? That should catch the changes.
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:IUAATech
ID: 18812302
tried that.

I get the following: CS0117: 'System.Web.UI.WebControls.GridViewUpdatedEventArgs' does not contain a definition for 'RowIndex'

I don't know how to access the RowIndex.

I am going nuts..... am I the only one with this kind of problem?
0
 
LVL 11

Accepted Solution

by:
lijunguo earned 500 total points
ID: 18812726
could please show us all of your codebehind file? How you bind your GV, in pageload, when you bind your GV, you should put them into
if not page.ispostback then
    bindGv()
end if
condition.
0
 

Author Comment

by:IUAATech
ID: 18816382
I feel really stupid now!!

all this time, I had the following:
    protected void Page_Load(object sender, EventArgs e)
    {
            gvAdminRights.DataBind();
    }

while I should have had
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gvAdminRights.DataBind();
    }

Thank you lijunguo for pointing this out. I feel much better... LOL
0
 
LVL 11

Expert Comment

by:lijunguo
ID: 18820344
You're welcome. Glad to hear it's solved. Sometimes I also forget something or put the wrong logic, spend some time to fix it when it should not have happened at all.

Regards,
Lijunguo
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question