views:

55

answers:

1

I am trying to update a DetailsView but I am getting the error "Parameters must be named". I assume that means there is a problem with the markup for the DetailsView. Here is the relevant code:

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

            <Fields>      

            <asp:TemplateField 
              HeaderText="Username">            
            <EditItemTemplate>
            <asp:TextBox 
              id="txtUserName"
              Text = '<%# Bind ("username") %>'
              runat = "server" />
            <asp:RequiredFieldValidator
              ID = "reqUserName"
              ControlToValidate = "txtUserName"
              Text = "(required)"
              Display = "Dynamic"
              runat = "server" />            
            </EditItemTemplate>
            <ItemTemplate>
              <asp:Label 
                id="UsernameLabel"
                runat="server"
                Text = '<%# Eval("username") %>' />
            </ItemTemplate>
            </asp:TemplateField>

          <asp:TemplateField 
            HeaderText="Date of birth">           
            <EditItemTemplate>
              <asp:TextBox 
                id="txtDOB"
                Text = '<%# Bind("dateofbirth") %>'
                runat = "server" />
              <asp:RangeValidator 
                runat="server" id="rngDOB" 
                controltovalidate="txtDOB" 
                type="Date" 
                minimumvalue="01-01-1930" 
                maximumvalue="01-01-2007" 
                errormessage="Please enter a valid date."
                HtmlEncode="false" />                        
            </EditItemTemplate>            
            <ItemTemplate>
              <asp:Label 
                id="DOBLabel"
                runat="server"                
                DataFormatString="{0:dd/MM/yyyy}"
                HtmlEncode="false"
                />
            </ItemTemplate>              
          </asp:TemplateField>           

               <asp:BoundField
               datafield="classday1"
               headertext="Class day 1"
               SortExpression="classday1"
               />

               <asp:BoundField ApplyFormatInEditMode="True" DataFormatString="<%=date()%>" />

            </Fields>
        </asp:DetailsView>

        <asp:SqlDataSource 
          ID="SqlDataSource1"
          runat="server" 
          ConnectionString="<%$ ConnectionStrings:FCLManager %>" ProviderName="MySql.Data.MySqlClient"
          SelectCommand="SELECT * from studentinfo WHERE centreID = @CentreID and fullname = @FullName"            
          UpdateCommand="UPDATE studentinfo SET username = @username, dateofbirth = @dateofbirth, classday1 = @classday1 WHERE studentID = @StudentID">

<UpdateParameters>   
            <asp:Parameter Name="username" Type="String" />
            <asp:Parameter Name="dateofbirth" Type="DateTime" />  <%--you can't use 'Date' on its own--%>
            <asp:Parameter Name="classday1" Type="String" />            
            </UpdateParameters>

        </asp:SqlDataSource>

This is a shortened version of my code but I think it shows the essentials.

Can anyone see what's wrong with this code?

A: 

I think there is problem with this statement

<asp:BoundField ApplyFormatInEditMode="True" DataFormatString="<%=date()%>" />

Remove this and check, becoz you don't have bind any field to boundfield. Like you did..

 <asp:BoundField
           datafield="classday1"
           headertext="Class day 1"
           SortExpression="classday1"
           />
Muhammad Akhtar
That was it, thanks, Muhammad - that has solved something that has bugged me for a long, long time!!
Dragon
@Dragon, If the answer is helpful, don't forget to mark as answer
Muhammad Akhtar