Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ASP.Net DetailsView EditItemTemplate Question

Posted on 2008-06-15
1
1,600 Views
Last Modified: 2012-06-21
Hi Guys,
I'm using ASP.net + Access + VB.net.
I have a edit function in a detailsview, but I don't want to users to edit a field called "Username". However, if I use "readonly" for Username field, the update will not work! Error message says "at least one parameter has no value". But I don't have Username in my update SQL. I don't understand why. If I include Username in the edit view, everything is fine. Can anyone please help me? Thanks
the code is:
<%@ Page Language="VB" MasterPageFile="~/Admin/AdminMasterPage.master" AutoEventWireup="false" CodeFile="StudentDetail.aspx.vb" Inherits="Admin_StudentDetail2" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
                    &nbsp;
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" BackColor="White"
        BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1"
        DataSourceID="AccessDataSourceBasicInfo" GridLines="None" Height="50px" Width="288px">
        <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
        <EditRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
        <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
        <Fields>
            <asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username"/>
            <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
            <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
            <asp:TemplateField HeaderText="SchoolID" SortExpression="SchoolID">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownSchoolID" runat="server" DataSourceID="AccessDataSourceSchool"
                        DataTextField="SchoolName" DataValueField="SchoolID" SelectedValue='<%# Bind("SchoolID") %>'>
                    </asp:DropDownList><asp:AccessDataSource ID="AccessDataSourceSchool" runat="server"
                        DataFile="~/App_Data/GLC.mdb" SelectCommand="SELECT [SchoolID], [SchoolName] FROM [Schools]">
                    </asp:AccessDataSource>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("SchoolID") %>'></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("SchoolID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="SchoolName" HeaderText="SchoolName" SortExpression="SchoolName" ReadOnly="True" />
            <asp:BoundField DataField="StudentID" HeaderText="StudentID" SortExpression="StudentID" />
            <asp:CommandField ShowEditButton="True" />
        </Fields>
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
        <HeaderTemplate>
                    Basic Information
        </HeaderTemplate>
    </asp:DetailsView>
                    
     <asp:AccessDataSource ID="AccessDataSourceBasicInfo" runat="server" DataFile="~/App_Data/GLC.mdb" 
      SelectCommand="SELECT Students.Username, Students.StudentID, Students.SchoolID, Students.LastName, Students.FirstName, Schools.SchoolName FROM (Students INNER JOIN Schools ON Students.SchoolID = Schools.SchoolID) WHERE (Students.Username = @Username)" 
      UpdateCommand="UPDATE Students SET Students.StudentID = @StudentID, Students.SchoolID = @SchoolID, Students.LastName = @LastName, Students.FirstName = @FirstName WHERE (Students.Username = @Username)" >
      <UpdateParameters>
       
       
       <asp:Parameter Name="StudentID" Type="String"/>
       <asp:Parameter Name="SchoolID" Type="int16"/>
       <asp:Parameter Name="LastName" Type="String"/>
       <asp:Parameter Name="FirstName" Type="String"/>
      
      </UpdateParameters>
      
    
    
    <SelectParameters>
       <asp:QUERYSTRINGPARAMETER DefaultValue="0" Name="Students.Username" QueryStringField="ID" />
    </SelectParameters>
    </asp:AccessDataSource>
</asp:Content>

Open in new window

0
Comment
Question by:Robertyue
1 Comment
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 250 total points
ID: 21790210
Try setting username to readonly, and also set the datakeynames value to username. Your sql statement does require the username parameter... (Students.Username = @Username)"
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question