Solved

GridView RowUpdating can not find edited information

Posted on 2007-03-27
7
415 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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 …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 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

11 Experts available now in Live!

Get 1:1 Help Now