Solved

GridView RowUpdating can not find edited information

Posted on 2007-03-27
7
419 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Name space syntax error 12 43
Runtime Error 2 28
Error in JQuery 5 39
ASP.net Run 3 sliders vertically as opposed to horizontally 9 20
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now