Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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):

XML
<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 :

C#
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
Comments
_Amy 5-Jul-12 2:39am    
It it changing in database?
mathidioticz 5-Jul-12 9:26am    
Hi. Nope, it is not changing..
mathidioticz 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900