Click here to Skip to main content
15,880,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So I know that this has been an occurring issue, but Ican't seem to find a solution to my this message. "FullName" was created trough "DropDownList1" by the following command in query builder "SELECT EmpID, FName, + ' ' LName AS FullName FROM Employee". "FullName" is supposed to be the data field that displays in the dropdownlist and EmpID is the value. I'm kind of new to visual studio and its languages. I hope someone can find what the problem is here, thanks in advance!

C#

C#
 namespace WebApplication2
{
    public partial class Recipe
    {
        protected global::System.Web.UI.WebControls.GridView GridView1;
        protected global::System.Web.UI.WebControls.SqlDataSource SqlDataSource1;
        protected global::System.Web.UI.WebControls.FormView FormView1;
        protected global::System.Web.UI.WebControls.SqlDataSource SqlDataSource2;
        protected global::System.Web.UI.WebControls.FormView FormView2;
        protected global::System.Web.UI.WebControls.SqlDataSource SqlDataSource3;
        protected global::System.Web.UI.WebControls.SqlDataSource SqlDataSource4;
        protected global::System.Web.UI.WebControls.SqlDataSource SqlDataSource5;
        protected global::System.Web.UI.WebControls.SqlDataSource SqlDataSource6;
    }
}


C#

C#
using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class Recipe : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void FormView1_PageIndexChanging(object sender,
        FormViewPageEventArgs e)
        {

        }

        protected void FormView2_PageIndexChanging(object sender,
        FormViewPageEventArgs e)
        {

        }
    }
}


ASP.NET

ASP.NET
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Recipe.aspx.cs" Inherits="WebApplication2.Recipe" %>
   <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
   </asp:Content>
   <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
       <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RecipeID" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display." OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowSorting="True">
           <Columns>
               <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
               <asp:BoundField DataField="RecipeID" HeaderText="RecipeID" ReadOnly="True" SortExpression="RecipeID" />
               <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
               <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
               <asp:BoundField DataField="Instructions" HeaderText="Instructions" SortExpression="Instructions" />
               <asp:BoundField DataField="EmpID" HeaderText="EmpID" SortExpression="EmpID" />
           </Columns>
       </asp:GridView>
       <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LABB7ConnectionString1 %>" DeleteCommand="DELETE FROM [Recipe] WHERE [RecipeID] = @RecipeID" InsertCommand="INSERT INTO [Recipe] ([Name], [Description], [Instructions], [EmpID]) VALUES (@Name, @Description, @Instructions, @EmpID)" ProviderName="<%$ ConnectionStrings:LABB7ConnectionString1.ProviderName %>" SelectCommand="SELECT [RecipeID], [Name], [Description], [Instructions], [EmpID] FROM [Recipe]" UpdateCommand="UPDATE [Recipe] SET [Name] = @Name, [Description] = @Description, [Instructions] = @Instructions, [EmpID] = @EmpID WHERE [RecipeID] = @RecipeID">
           <DeleteParameters>
               <asp:Parameter Name="RecipeID" Type="Int64" />
           </DeleteParameters>
           <InsertParameters>
               <asp:Parameter Name="Name" Type="String" />
               <asp:Parameter Name="Description" Type="String" />
               <asp:Parameter Name="Instructions" Type="String" />
               <asp:Parameter Name="EmpID" Type="Int64" />
           </InsertParameters>
           <UpdateParameters>
               <asp:Parameter Name="Name" Type="String" />
               <asp:Parameter Name="Description" Type="String" />
               <asp:Parameter Name="Instructions" Type="String" />
               <asp:Parameter Name="EmpID" Type="Int64" />
               <asp:Parameter Name="RecipeID" Type="Int64" />
           </UpdateParameters>
       </asp:SqlDataSource>
       <asp:FormView ID="FormView1" runat="server" DataKeyNames="RecipeID" DataSourceID="SqlDataSource2" DefaultMode="Insert" OnPageIndexChanging="FormView1_PageIndexChanging" Width="226px">
           <EditItemTemplate>
               RecipeID:
               <asp:Label ID="RecipeIDLabel1" runat="server" Text='<%# Eval("RecipeID") %>' />
               <br />
               Name:
               <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
               <br />
               Description:
               <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
               <br />
               Instructions:
               <asp:TextBox ID="InstructionsTextBox" runat="server" Text='<%# Bind("Instructions") %>' />
               <br />
               EmpID:
               <asp:TextBox ID="EmpIDTextBox" runat="server" Text='<%# Bind("EmpID") %>' />
               <br />
               <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
                <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
           </EditItemTemplate>
           <InsertItemTemplate>
               Name:
               <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
               <br />
               Description:
               <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
               <br />
               Instructions:
               <asp:TextBox ID="InstructionsTextBox" runat="server" Text='<%# Bind("Instructions") %>' />
               <br />
               EmpID:
               <asp:DropDownList ID="DropDownList1" SelectedValue='<%# Bind("EmpID") %>' runat="server" DataSourceID="SqlDataSource3" DataTextField="FullName" DataValueField="EmpID">
       </asp:DropDownList>
               <br />
               <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
                <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
           </InsertItemTemplate>
           <ItemTemplate>
               RecipeID:
               <asp:Label ID="RecipeIDLabel" runat="server" Text='<%# Eval("RecipeID") %>' />
               <br />
               Name:
               <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
               <br />
               Description:
               <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Bind("Description") %>' />
               <br />
               Instructions:
               <asp:Label ID="InstructionsLabel" runat="server" Text='<%# Bind("Instructions") %>' />
               <br />
               EmpID:
               <asp:Label ID="EmpIDLabel" runat="server" Text='<%# Bind("EmpID") %>' />
               <br />
               <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
                <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" />
                <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />
           </ItemTemplate>
       </asp:FormView>
       <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:LABB7ConnectionString1 %>" DeleteCommand="DELETE FROM [Recipe] WHERE [RecipeID] = @RecipeID" InsertCommand="INSERT INTO [Recipe] ([Name], [Description], [Instructions], [EmpID]) VALUES (@Name, @Description, @Instructions, @EmpID)" SelectCommand="SELECT EmpID, FName + ' ' + LName AS FullName FROM Employee" UpdateCommand="UPDATE [Recipe] SET [Name] = @Name, [Description] = @Description, [Instructions] = @Instructions, [EmpID] = @EmpID WHERE [RecipeID] = @RecipeID">
           <DeleteParameters>
               <asp:Parameter Name="RecipeID" Type="Int64" />
           </DeleteParameters>
           <InsertParameters>
               <asp:Parameter Name="Name" Type="String" />
               <asp:Parameter Name="Description" Type="String" />
               <asp:Parameter Name="Instructions" Type="String" />
               <asp:Parameter Name="EmpID" Type="Int64" />
           </InsertParameters>
           <UpdateParameters>
               <asp:Parameter Name="Name" Type="String" />
               <asp:Parameter Name="Description" Type="String" />
               <asp:Parameter Name="Instructions" Type="String" />
               <asp:Parameter Name="EmpID" Type="Int64" />
               <asp:Parameter Name="RecipeID" Type="Int64" />
           </UpdateParameters>
       </asp:SqlDataSource>
       <br />
       Lägg till ingrediens<br />
       <asp:FormView ID="FormView2" runat="server" DataKeyNames="IngredientID,RecipeID" DataSourceID="SqlDataSource3" DefaultMode="Insert" OnPageIndexChanging="FormView2_PageIndexChanging">
           <EditItemTemplate>
               IngredientID:
               <asp:Label ID="IngredientIDLabel1" runat="server" Text='<%# Eval("IngredientID") %>' />
               <br />
               RecipeID:
               <asp:Label ID="RecipeIDLabel1" runat="server" Text='<%# Eval("RecipeID") %>' />
               <br />
               amount:
               <asp:TextBox ID="amountTextBox" runat="server" Text='<%# Bind("amount") %>' />
               <br />
               unit:
               <asp:TextBox ID="unitTextBox" runat="server" Text='<%# Bind("unit") %>' />
               <br />
               <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
                <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
           </EditItemTemplate>
           <InsertItemTemplate>
               IngredientID:
                <asp:DropDownList ID="DropDownList2" SelectedValue='<%# Bind("IngredientID") %>' runat="server" DataSourceID="SqlDataSource4" DataTextField="Name" DataValueField="IngredientID">
       </asp:DropDownList>
               <br />
               RecipeID:
               <asp:DropDownList ID="DropDownList3" SelectedValue='<%# Bind("RecipeID") %>' runat="server" DataSourceID="SqlDataSource5" DataTextField="Name" DataValueField="RecipeID">
       </asp:DropDownList>
               <br />
               amount:
               <asp:TextBox ID="amountTextBox" runat="server" Text='<%# Bind("amount") %>' />
               <br />
               unit:
               <asp:DropDownList ID="DropDownList4" SelectedValue='<%# Bind("unit") %>' runat="server" DataSourceID="SqlDataSource6" DataTextField="unit" DataValueField="unit">
       </asp:DropDownList>
               <br />
               <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
                <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
           </InsertItemTemplate>
           <ItemTemplate>
               Ingredient:
               <asp:Label ID="IngredientIDLabel" runat="server" Text='<%# Eval("IngredientID") %>' />
               <br />
               Recipe:
               <asp:Label ID="RecipeIDLabel" runat="server" Text='<%# Eval("RecipeID") %>' />
               <br />
               amount:
               <asp:Label ID="amountLabel" runat="server" Text='<%# Bind("amount") %>' />
               <br />
               unit:
               <asp:Label ID="unitLabel" runat="server" Text='<%# Bind("unit") %>' />
               <br />
               <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
                <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" />
                <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />
           </ItemTemplate>
       </asp:FormView>
       <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:LABB7ConnectionString1 %>" DeleteCommand="DELETE FROM [RecipeIngredient] WHERE [IngredientID] = @IngredientID AND [RecipeID] = @RecipeID" InsertCommand="INSERT INTO [RecipeIngredient] ([IngredientID], [RecipeID], [amount], [unit]) VALUES (@IngredientID, @RecipeID, @amount, @unit)" SelectCommand="SELECT * FROM [RecipeIngredient]" UpdateCommand="UPDATE [RecipeIngredient] SET [amount] = @amount, [unit] = @unit WHERE [IngredientID] = @IngredientID AND [RecipeID] = @RecipeID">
           <DeleteParameters>
               <asp:Parameter Name="IngredientID" Type="Int64" />
               <asp:Parameter Name="RecipeID" Type="Int64" />
           </DeleteParameters>
           <InsertParameters>
               <asp:Parameter Name="IngredientID" Type="Int64" />
               <asp:Parameter Name="RecipeID" Type="Int64" />
               <asp:Parameter Name="amount" Type="Int32" />
               <asp:Parameter Name="unit" Type="String" />
           </InsertParameters>
           <UpdateParameters>
               <asp:Parameter Name="amount" Type="Int32" />
               <asp:Parameter Name="unit" Type="String" />
               <asp:Parameter Name="IngredientID" Type="Int64" />
               <asp:Parameter Name="RecipeID" Type="Int64" />
           </UpdateParameters>
       </asp:SqlDataSource>
       <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:LABB7ConnectionString1 %>" SelectCommand="SELECT [IngredientID], [Name] FROM [Ingredient]"></asp:SqlDataSource>
       <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:LABB7ConnectionString1 %>" SelectCommand="SELECT [Name], [RecipeID] FROM [Recipe]"></asp:SqlDataSource>
       <asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:LABB7ConnectionString1 %>" SelectCommand="SELECT * FROM [Unit]"></asp:SqlDataSource>
   </asp:Content>


What I have tried:

I have been trying to figure out where "FullName" is missing
Posted
Updated 21-Feb-21 17:30pm
v4

1 solution

DropDownList ID="DropDownList1" SelectedValue='<%# Bind("EmpID") %>' runat="server" DataSourceID="SqlDataSource3" DataTextField="FullName" DataValueField="EmpID"


Your SqlDataSource3 does not have the fields FullName & EmpID.

SqlDataSource2 seems to be the right datasource for it.
 
Share this answer
 

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