Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I having this problem, and I seriously cannot figure out what is wrong with the code.. I had researched for weeks yet the same problem keep persist.
 
I have a webform called UserProfile.aspx. After user logged-in, they can view and edit their particulars at UserProfile. I used a SqlDataSource and was binding the data to a DetailsView. In the details view, it retrieved data from 3 tables and the selecting query works fine and could display data successfully.
 
However, when I update the information and hit on the Update button in the DetailsView, it page post back after the update button is pressed with no change to it.
 
Following is the code which I get the current logged-in user(inside UserProfile.aspx):
 
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
         ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>"
 

           SelectCommand="SELECT aspnet_Membership.Email, Details.CustName, Details.CustNum, Details.CustRole, Details.CustStatus, Details.PName, Details.PEmail, Details.PRole, Details.WedDate, aspnet_Users.UserName FROM Details INNER JOIN aspnet_Membership ON Details.UserId = aspnet_Membership.UserId INNER JOIN aspnet_Users ON aspnet_Membership.UserId = aspnet_Users.UserId WHERE Details.UserId = @UserId"
           onselecting="SqlDataSource1_Selecting"
 

             UpdateCommand="UPDATE Details SET CustName = @CustName, CustNum = @CustNum, CustRole = @CustRole, CustStatus = @CustStatus, PName = @PName, PEmail = @PEmail, PRole = @PRole, WedDate = @WedDate WHERE [UserId] = @UserId">
 
           <SelectParameters>
               <asp:Parameter Name="UserId" type="String" />
           </SelectParameters>
 
           <UpdateParameters>
              <asp:Parameter Name="UserId" type="String" />
               <asp:Parameter Name="CustName" type="String"  />
               <asp:Parameter Name="CustNum" type="String" />
               <asp:Parameter Name="CustRole" type="String" />
               <asp:Parameter Name="CustStatus" type="String" />
               <asp:Parameter Name="PName" type="String" />
               <asp:Parameter Name="PEmail" type="String"  />
               <asp:Parameter Name="PRole" type="String"  />
               <asp:Parameter Name="WedDate" type="String" />
           </UpdateParameters>
 
       </asp:SqlDataSource>
 

 
       <br />
       <asp:DetailsView ID="DetailsView1" runat="server"
           AutoGenerateRows="False"
           DataSourceID="SqlDataSource1"
           Height="29px"
           Width="476px"
           DataKeyNames="UserName"
          >
 

           <Fields>
               <asp:BoundField DataField="UserName" HeaderText="UserName"
                   SortExpression="UserName" ReadOnly="True" />
 
               <asp:BoundField DataField="Email" HeaderText="Email"
                   SortExpression="Email" />
 

 

               <asp:BoundField DataField="CustName" HeaderText="CustName"
                   SortExpression="CustName" />
 
               <asp:BoundField DataField="CustNum" HeaderText="CustNum"
                   SortExpression="CustNum" />
 
               <asp:BoundField DataField="CustRole" HeaderText="CustRole"
                   SortExpression="CustRole" />
               <asp:BoundField DataField="CustStatus" HeaderText="CustStatus"
                   SortExpression="CustStatus" />
               <asp:BoundField DataField="PName" HeaderText="PName"
                   SortExpression="PName" />
               <asp:BoundField DataField="PEmail" HeaderText="PEmail"
                   SortExpression="PEmail" />
               <asp:BoundField DataField="PRole" HeaderText="PRole"
                   SortExpression="PRole" />
               <asp:BoundField DataField="WedDate" HeaderText="WedDate"
                   SortExpression="WedDate" />
               <asp:CommandField ShowEditButton="True" />
 
           </Fields>
           <PagerTemplate>
               <br />
           </PagerTemplate>
       </asp:DetailsView>
 
This is the code in my UserProfile.aspx.cs :
 
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        // Get a reference to the currently logged on user
        MembershipUser currentUser = Membership.GetUser();
 
        // Determine the currently logged on user's UserId value
        // Assign the currently logged on user's UserId to the @UserId parameter
        //access the parameter value using e.Command.Parameters
        //programmatically set the @UserId:

        e.Command.Parameters["@UserId"].Value = currentUser.ProviderUserKey.ToString();
 
        Response.Write(currentUser.ProviderUserKey.ToString());
    //When I run the webform, the UserId of the current logged-in user had displayed, 
    // the @UserId was not empty. 
    }
Posted 4-Jul-12 21:07pm
Comments
A_K_ at 5-Jul-12 2:39am
   
It it changing in database?
junetanweiting at 5-Jul-12 9:26am
   
Hi. Nope, it is not changing..
junetanweiting at 5-Jul-12 9:29am
   
If i take out the WHERE clause from the update query, the detailsview can update sucessfully, however the new updated value will update all the records in that table instead of just that particular record.. if i add in the WHERE clause, the problem are just like above explained post.. "page post back after the update button is pressed with no change to it"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 319
2 CPallini 275
3 DamithSL 214
4 Maciej Los 185
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 5 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100