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)
{
MembershipUser currentUser = Membership.GetUser();
e.Command.Parameters["@UserId"].Value = currentUser.ProviderUserKey.ToString();
Response.Write(currentUser.ProviderUserKey.ToString());
}