views:

421

answers:

1

After editing some fields, clicking on Update doesn't show the new values. I have tried two ways to retrieve the new values as you can see from this shortened version of the ItemUpdating event (and both return the old ones) :-

 Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles DetailsView1.ItemUpdating

    Dim txtPassword As TextBox = CType(DetailsView1.Rows(1).Cells(1).FindControl("txtPassword"), TextBox)
    Struct_Student.password = txtPassword.Text

    Dim PasswordValue As String = e.NewValues("password").ToString()
    Struct_Student.password = PasswordValue         

End Sub

Here is a shortened version of the aspx :-

<asp:Content ID="Content1" ContentPlaceHolderID="cpMainContent" Runat="Server">      
 <div id="Controls">     
 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
   <ContentTemplate>   

   <asp:DetailsView ID="DetailsView1"
      runat="server"
      AutoGenerateRows="False" 
      DataKeyNames="student_id" DataSourceID="SqlDataSource1" 
      ForeColor="Blue"
      BackColor="#FFF7E6"            
      AutoPostBack="True"                        
      AutoGenerateEditButton = True
      AutoGenerateInsertButton = True
      OnModeChanging="StudentDetailView_ModeChanging"                         
      Height=163px
      Width=327px              
      style="left: 400px; top: 1px; position: absolute;">  

        <Fields>                             

        <asp:TemplateField 
          HeaderText="Password">
        <EditItemTemplate>
        <asp:TextBox 
          id="txtPassword"
          Text = '<%# Bind ("password") %>'
          runat = "server" />
        <asp:RequiredFieldValidator
          ID = "reqPassword"
          ControlToValidate = "txtPassword"
          Text = "(required)"
          Display = "Dynamic"
          runat = "server" />            
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label 
            id="PasswordLabel"
            runat="server"
            Text = '<%# Eval("password") %>' />
        </ItemTemplate>
        </asp:TemplateField>       

         <asp:BoundField
           datafield="emailaddress"
           headertext="Email address"
           SortExpression="emailaddress"
           />

        </Fields>
    </asp:DetailsView>

    <asp:SqlDataSource 
      ID="SqlDataSource1"
      runat="server" 
      ConnectionString="<%$ ConnectionStrings:FCLManager %>" ProviderName="MySql.Data.MySqlClient"
      SelectCommand="Select * from tblstudentinfo WHERE centre_id = @CentreID and fullname = @FullName"            
      <SelectParameters>         
        <asp:Parameter Name="CentreID" Type="Int16" DefaultValue="0" />
        <asp:Parameter Name="FullName" Type="String" DefaultValue="0" />
      </SelectParameters>

    </asp:SqlDataSource>         
    </ContentTemplate>           
</asp:UpdatePanel>              
</div>   <%--Controls div--%>          
</asp:Content>
A: 

I think you missing UpdateCommand in your SQLdatasource

Since your detailsview in updatepanle, you will directly get control in DetailsView1_ItemUpdating event rather finding control from detailsview

txtPassword.Text

Muhammad Akhtar
Thank you, Muhammad, you were right! I now have an UpdateCommand and the new values are showing in the DetailsView1_ItemUpdating event. What is supposed to happen now? When I click on Update the edit textboxes are still there and the record stays the same.I thought the update was automatic - what have I missed?
Dragon
In your sql datasource, no update method provided and update parameter as well. you need to provide update method name and update parameter to update the record
Muhammad Akhtar