Solved

GridView RowUpdating can not find edited information

Posted on 2007-03-27
7
423 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

820 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