DETAILSVIEW DropDownList

Posts   
 
    
Posts: 11
Joined: 15-Nov-2007
# Posted on: 15-Nov-2007 15:59:38   

hi

I want to insert a person by selecting the firma (company) by a dropdownlist instead of writing a firma (company) in a textbox. Is it possible?

Example: <ASP: DETAILSVIEW id="DetailsView1" runat="server" autogeneraterows="False" datakeynames="Id" datasourceid="LLBLGenProDataSource1" height="50px" width="125px">

<FIELDS> <ASP:BOUNDFIELD datafield="Id" headertext="Id" insertvisible="False" readonly="True" sortexpression="Id" /> <ASP:BOUNDFIELD datafield="Vorname" headertext="Vorname" sortexpression="Vorname" /> <ASP:BOUNDFIELD datafield="Nachname" headertext="Nachname" sortexpression="Nachname" /> <ASP:BOUNDFIELD datafield="FirmaId" headertext="FirmaId" sortexpression="FirmaId" />

<ASP:TEMPLATEFIELD headertext="Firma"> <ITEMTEMPLATE> <ASP:LABEL runat="server" id="L_Firma" text='<%# Bind("FirmaName") %>'></ASP:LABEL> </ITEMTEMPLATE> <INSERTITEMTEMPLATE> <ASP: DROPDOWNLIST runat="server" id="DDL_Firmen" datasourceid="LLBLGenProDataSource2" datatextfield="Name" datavaluefield="Id"> </ASP: DROPDOWNLIST> </INSERTITEMTEMPLATE> </ASP:TEMPLATEFIELD>

<ASP:COMMANDFIELD showinsertbutton="True" />

</FIELDS> </ASP: DETAILSVIEW>

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Nov-2007 17:13:20   

Yes, is possible simple_smile Do you have a related field between Person and Company. For example: Person.CompanyId -> Company.CompanyId ? or you just have a Person.FirmName that you want to fill based on the existing Companies?

David Elizondo | LLBLGen Support Team
Posts: 11
Joined: 15-Nov-2007
# Posted on: 16-Nov-2007 09:28:01   

Hi Daelmo, i have both. A Person.FirmName to display the FirmName and a related field between Person and Company.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 16-Nov-2007 10:47:56   

All you have to do is to bind the SelectedValue of the DropDownList to the FirmaId or FirmaName, whichever you have on the PersonTable. Hint: make sure you define the corresponding field to be the value field of the DDL.

<INSERTITEMTEMPLATE> <ASP: DROPDOWNLIST runat="server" id="DDL_Firmen" datasourceid="LLBLGenProDataSource2" datatextfield="Name" datavaluefield="Id" SelectedValue='<%# Bind("FirmaName") %>' >

Posts: 11
Joined: 15-Nov-2007
# Posted on: 19-Nov-2007 10:55:29   

Thanks, now it works.

But unfortunately if i insert a new person concurrently there is a new company in table Companys.

I would like a new person only.

markus

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 19-Nov-2007 17:10:14   

Hi markus, I can't figured out at your last post whether you need further assistance.

Posts: 11
Joined: 15-Nov-2007
# Posted on: 19-Nov-2007 17:16:32   

I'm sorry.

My problem is after i write a new person in my detailsview there are one new entry in my customer table (thats fine) and one in my company table with the preselected company from my detailsview (thats not fine wink )

I want only a new customer in my customer table without a new company entry in my company table.

the dropdownlist is only for selecting a company for the new customer.

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 19-Nov-2007 17:21:14   

Could you please post your finally version of the declarative ASPX (including the LLBLGenDataSource declaration part) and the relevante behind code?

Posts: 11
Joined: 15-Nov-2007
# Posted on: 19-Nov-2007 17:25:10   

there is no code in my codebehind file

<%@ PAGE language="C#" autoeventwireup="true" codefile="Insert.aspx.cs" inherits="Insert" %>

<%@ REGISTER assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" namespace="SD.LLBLGen.Pro.ORMSupportClasses"
    tagprefix="llblgenpro" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <LLBLGENPRO:LLBLGENPRODATASOURCE id="LLBLGenProDataSource1" runat="server" datacontainertype="EntityCollection"
                entitycollectiontypename="DALRep.CollectionClasses.PersonenCollection, DALRep"
                onentityinserting="LLBLGenProDataSource1_EntityInserting">
            </LLBLGENPRO:LLBLGENPRODATASOURCE>
            <LLBLGENPRO:LLBLGENPRODATASOURCE id="LLBLGenProDataSource2" runat="server" datacontainertype="EntityCollection"
                entitycollectiontypename="DALRep.CollectionClasses.FirmaCollection, DALRep">
            </LLBLGENPRO:LLBLGENPRODATASOURCE>          
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <ASP:DETAILSVIEW id="DetailsView1" runat="server" autogeneraterows="False" datakeynames="Id"
                datasourceid="LLBLGenProDataSource1" height="50px" width="125px">
                <FIELDS>
                    <ASP:BOUNDFIELD datafield="Id" headertext="Id" insertvisible="False" readonly="True"
                        sortexpression="Id" />
                    <ASP:BOUNDFIELD datafield="Vorname" headertext="Vorname" sortexpression="Vorname" />
                    <ASP:BOUNDFIELD datafield="Nachname" headertext="Nachname" sortexpression="Nachname" />
                    <ASP:BOUNDFIELD datafield="Email" headertext="Email" sortexpression="Email" />
                    <ASP:BOUNDFIELD datafield="Passwort" headertext="Passwort" sortexpression="Passwort" />
                    <ASP:BOUNDFIELD datafield="Gehalt" headertext="Gehalt" sortexpression="Gehalt" />
                    <ASP:BOUNDFIELD datafield="ManagerId" headertext="ManagerId" sortexpression="ManagerId" />
                    <ASP:BOUNDFIELD datafield="ContactId" headertext="ContactId" sortexpression="ContactId" />
                    <ASP:TEMPLATEFIELD headertext="Firma">
                        <ITEMTEMPLATE>
                            <ASP:LABEL runat="server" id="LABEL2" text='<%# Bind("FirmaName") %>'></ASP:LABEL>
                        </ITEMTEMPLATE>
                        <INSERTITEMTEMPLATE>
                            <ASP:DROPDOWNLIST runat="server" id="DDL_Firmen" datasourceid="LLBLGenProDataSource2"
                                datatextfield="Name" datavaluefield="Id" selectedvalue='<%# Bind("FirmaName") %>'>
                            </ASP:DROPDOWNLIST>
                        </INSERTITEMTEMPLATE>
                    </ASP:TEMPLATEFIELD>
                    <ASP:COMMANDFIELD showinsertbutton="True" />
                </FIELDS>
            </ASP:DETAILSVIEW>
        </div>
    </form>
</body>
</html>





Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Nov-2007 10:16:23   

<LLBLGENPRO:LLBLGENPRODATASOURCE id="LLBLGenProDataSource1" runat="server" datacontainertype="EntityCollection" entitycollectiontypename="DALRep.CollectionClasses.PersonenCollection, DALRep" onentityinserting="LLBLGenProDataSource1_EntityInserting">

Are you sure there is no code behind? simple_smile

Posts: 11
Joined: 15-Nov-2007
# Posted on: 20-Nov-2007 10:33:35   

OK a method is there wink :

protected void LLBLGenProDataSource1_EntityInserting(object sender, SD.LLBLGen.Pro.ORMSupportClasses.CancelableDataSourceActionEventArgs e) { //DropDownList ddl_firmen = (DropDownList)FindControl("DetailsView1").Controls[0].Controls[9].Controls[1].FindControl("DDL_Firmen");

    //Control test = null;
    //FindControl1(FindControl("DetailsView1").Controls, ref test);

    //e.InvolvedEntity.SetNewFieldValue("FirmaId", ((DropDownList)test).SelectedValue);
}
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Nov-2007 10:53:00   

mmmm.

Would you please examine the generated SQL Queries at runtime, to see if any Inserts in that table are generated?

Posts: 11
Joined: 15-Nov-2007
# Posted on: 20-Nov-2007 10:58:24   

Company:

declare @p3 int set @p3=9 exec sp_executesql N'INSERT INTO [Personen].[dbo].[Firma] ([Name]) VALUES (@Name);SELECT @Id=SCOPE_IDENTITY()',N'@Id int output,@Name nvarchar(20)',@Id=@p3 output,@Name=N'1' select @p3

Person:

declare @p3 int set @p3=78 exec sp_executesql N'INSERT INTO [Personen].[dbo].[Personen] ([Vorname], [Nachname], [Email], [Passwort], [FirmaID], [Gehalt], [ManagerID], [ContactID]) VALUES (@Vorname, @Nachname, @Email, @Passwort, @FirmaId, @Gehalt, @ManagerId, @ContactId);SELECT @Id=SCOPE_IDENTITY()',N'@Id int output,@Vorname nvarchar(20),@Nachname nvarchar(20),@Email nvarchar(20),@Passwort nvarchar(20),@FirmaId int,@Gehalt int,@ManagerId int,@ContactId int',@Id=@p3 output,@Vorname=N'vorname',@Nachname=N'nachname',@Email=N'email', @Passwort=N'password',@FirmaId=9,@Gehalt=1234,@ManagerId=1,@ContactId=2 select @p3

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 20-Nov-2007 11:51:29   

What are the: LLBLgen Pro version, runtime lib build number? http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7720

It seems a new Company entity is assigned to a fetched person. The HTML seems OK and you don't have a reference to the Firma field in the HTML it seems.

The combobox does show values to select from?

Frans Bouma | Lead developer LLBLGen Pro
Posts: 11
Joined: 15-Nov-2007
# Posted on: 20-Nov-2007 15:26:50   

Version:

2.5 Final Demo

ComboBox: <select name="DetailsView1$DDL_Firmen" id="DetailsView1_DDL_Firmen"> <option value="1">webix</option> <option value="2">hp</option> <option value="8">1</option> <option value="9">1</option>

        </select>
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Nov-2007 09:13:12   

2.5 Final Demo

That's not the LLBLGen Pro runtime library version. Please check the link posted by Frans.

Posts: 11
Joined: 15-Nov-2007
# Posted on: 21-Nov-2007 09:28:21   

Fileversion: 2.5.07.1019

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 21-Nov-2007 13:17:09   

I can't repro it. Though I think you made a mistake: this:


 <ITEMTEMPLATE>
                            <ASP:LABEL runat="server" id="LABEL2" text='<%# Bind("FirmaName") %>'></ASP:LABEL>
                        </ITEMTEMPLATE>
                        <INSERTITEMTEMPLATE>
                            <ASP:DROPDOWNLIST runat="server" id="DDL_Firmen" datasourceid="LLBLGenProDataSource2"
                                datatextfield="Name" datavaluefield="Id" selectedvalue='<%# Bind("FirmaName") %>'>
                            </ASP:DROPDOWNLIST>
                        </INSERTITEMTEMPLATE>

should be:


 <ITEMTEMPLATE>
                            <ASP:LABEL runat="server" id="LABEL2" text='<%# Bind("FirmaID") %>'></ASP:LABEL>
                        </ITEMTEMPLATE>
                        <INSERTITEMTEMPLATE>
                            <ASP:DROPDOWNLIST runat="server" id="DDL_Firmen" datasourceid="LLBLGenProDataSource2"
                                datatextfield="Name" datavaluefield="Id" selectedvalue='<%# Bind("FirmaID") %>'>
                            </ASP:DROPDOWNLIST>
                        </INSERTITEMTEMPLATE>

as you're binding in the detailsview the PERSON entity, so you can only refer to these fields. You have to bind to the FirmaID, which is the FK in person.

I've done this in my repro, works OK.


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ REGISTER assembly="SD.LLBLGen.Pro.ORMSupportClasses" namespace="SD.LLBLGen.Pro.ORMSupportClasses"  tagprefix="llblgenpro" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <LLBLGENPRO:LLBLGENPRODATASOURCE id="LLBLGenProDataSource1" runat="server" datacontainertype="EntityCollection" 
            EntityCollectionTypeName="Northwind.DAL.CollectionClasses.CustomerCollection, Northwind.DAL"
                >
            </LLBLGENPRO:LLBLGENPRODATASOURCE>
            <LLBLGENPRO:LLBLGENPRODATASOURCE id="LLBLGenProDataSource2" runat="server" datacontainertype="EntityCollection" 
            EntityCollectionTypeName="Northwind.DAL.CollectionClasses.OrderCollection, Northwind.DAL"
                >
                <SelectParameters>
                    <asp:Parameter DefaultValue="CHOPS" Name="CustomerId" />
                </SelectParameters>
            </LLBLGENPRO:LLBLGENPRODATASOURCE>          
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <ASP:DETAILSVIEW id="DetailsView1" runat="server" autogeneraterows="False" datakeynames="OrderId"
                datasourceid="LLBLGenProDataSource2" height="50px" width="125px">
                <Fields>
                    <asp:BoundField DataField="OrderId" HeaderText="OrderId" InsertVisible="False" ReadOnly="True" SortExpression="OrderId" />
                    <asp:TemplateField HeaderText="CustomerId" SortExpression="CustomerId">
                        <InsertItemTemplate>
                            <ASP:DROPDOWNLIST runat="server" id="DDL_Customer" datasourceid="LLBLGenProDataSource1"
                                datatextfield="CompanyName" datavaluefield="CustomerId" selectedvalue='<%# Bind("CustomerId") %>'/>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("CustomerId") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="EmployeeId" HeaderText="EmployeeId" SortExpression="EmployeeId" />
                    <asp:BoundField DataField="OrderDate" HeaderText="OrderDate" SortExpression="OrderDate" />
                    <asp:BoundField DataField="RequiredDate" HeaderText="RequiredDate" SortExpression="RequiredDate" />
                    <asp:BoundField DataField="ShippedDate" HeaderText="ShippedDate" SortExpression="ShippedDate" />
                    <asp:BoundField DataField="ShipVia" HeaderText="ShipVia" SortExpression="ShipVia" />
                    <asp:BoundField DataField="Freight" HeaderText="Freight" SortExpression="Freight" />
                    <asp:BoundField DataField="ShipName" HeaderText="ShipName" SortExpression="ShipName" />
                    <asp:BoundField DataField="ShipAddress" HeaderText="ShipAddress" SortExpression="ShipAddress" />
                    <asp:BoundField DataField="ShipCity" HeaderText="ShipCity" SortExpression="ShipCity" />
                    <asp:BoundField DataField="ShipRegion" HeaderText="ShipRegion" SortExpression="ShipRegion" />
                    <asp:BoundField DataField="ShipPostalCode" HeaderText="ShipPostalCode" SortExpression="ShipPostalCode" />
                    <asp:BoundField DataField="ShipCountry" HeaderText="ShipCountry" SortExpression="ShipCountry" />
                    <ASP:COMMANDFIELD showinsertbutton="True" />
                </Fields>
            </ASP:DETAILSVIEW>
        </div>
    </form>
</body>
</html>

Frans Bouma | Lead developer LLBLGen Pro
Posts: 11
Joined: 15-Nov-2007
# Posted on: 23-Nov-2007 11:00:47   

Hello Otis your northwind example works pretty nice

after editing my code a new person would be inserted. But the person have every time the default INSERTPARAMETER (FirmaId). Without a insertparameter i get an errormessage: "Cannot insert the value NULL into column 'FirmaID', table 'Personen.dbo.Personen'; column does not allow nulls. INSERT fails. The statement has been terminated."

  <LLBLGENPRO:LLBLGENPRODATASOURCE id="LLBLGenProDataSource1" runat="server" datacontainertype="EntityCollection"
                entitycollectiontypename="DALRep.CollectionClasses.FirmaCollection, DALRep">
            </LLBLGENPRO:LLBLGENPRODATASOURCE>
            
            <LLBLGENPRO:LLBLGENPRODATASOURCE id="LLBLGenProDataSource2" runat="server" datacontainertype="EntityCollection"
                entitycollectiontypename="DALRep.CollectionClasses.PersonenCollection, DALRep">
                <INSERTPARAMETERS>
                    <asp:Parameter DefaultValue="1" Name="FirmaId" />
                </INSERTPARAMETERS>
                
            </LLBLGENPRO:LLBLGENPRODATASOURCE>
            <ASP:DETAILSVIEW id="DetailsView1" runat="server" autogeneraterows="False" datakeynames="PersonId"
                datasourceid="LLBLGenProDataSource2" height="50px" width="125px">
                <FIELDS>
                    <ASP:BOUNDFIELD datafield="PersonId" headertext="PersonId" insertvisible="False"
                        readonly="True" sortexpression="PersonId" />
                    <ASP:TEMPLATEFIELD headertext="FirmaID" sortexpression="FirmaID">
                        <INSERTITEMTEMPLATE>
                            <ASP:DROPDOWNLIST runat="server" id="DDL_Firmen" datasourceid="LLBLGenProDataSource1"
                                datatextfield="Name" datavaluefield="FirmaId" selectedvalue='<%# Bind("FirmaID") %>'>
                            </ASP:DROPDOWNLIST>
                        </INSERTITEMTEMPLATE>
                        <ITEMTEMPLATE>
                            <ASP:LABEL runat="server" id="LABEL2" text='<%# Bind("FirmaId") %>'></ASP:LABEL>
                        </ITEMTEMPLATE>
                    </ASP:TEMPLATEFIELD>
                    <ASP:BOUNDFIELD datafield="Vorname" headertext="Vorname" sortexpression="Vorname" />
                    <ASP:BOUNDFIELD datafield="Nachname" headertext="Nachname" sortexpression="Nachname" />
                    <ASP:COMMANDFIELD showinsertbutton="True" />
                </FIELDS>
            </ASP:DETAILSVIEW>


Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-Nov-2007 16:15:02   

I think it's a case sensetive issue simple_smile

<INSERTITEMTEMPLATE> <ASPsmile ROPDOWNLIST runat="server" id="DDL_Firmen" datasourceid="LLBLGenProDataSource1" datatextfield="Name" datavaluefield="FirmaId" selectedvalue='<%# **Bind("FirmaID") **%>'> </ASPsmile ROPDOWNLIST>

Should be:

<INSERTITEMTEMPLATE> <ASPsmile ROPDOWNLIST runat="server" id="DDL_Firmen" datasourceid="LLBLGenProDataSource1" datatextfield="Name" datavaluefield="FirmaId" selectedvalue='<%# **Bind("FirmaId") **%>'> </ASPsmile ROPDOWNLIST>

Please check it out.

Posts: 11
Joined: 15-Nov-2007
# Posted on: 26-Nov-2007 08:15:51   

i have change the "id" in upper and lower case -> same error and "id" in Id and so on...

in my database the id fields are = PersonId and FirmaId In FirmaEntity.cs = FirmaId In PersonenEntity.cs = PersonId

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 26-Nov-2007 09:19:43   

What's the problem exactly: still the phantom insert of a related entity? Because we can't reproduce that, I posted all the code I have used to do that and you can verify that.

If it's another problem, please elaborate more, as I'm a little confused what's exactly the problem: a different one, or the same. (as the form code is different)

Frans Bouma | Lead developer LLBLGen Pro