Solved

GridView RowUpdating can not find edited information

Posted on 2007-03-27
7
429 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

632 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