Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...LINQ to SQL - how to databind a dropdownlist to a table, but get DataTextField from related tableLINQ to SQL - how to databind a dropdownlist to a table, but get DataTextField from related table
Previous
 
Next
New Post
2/17/2009 8:08 PM
 

In code, with LINQ to SQL you can easily reference a column in a related table, but it seems like you can't do this when databinding controls.

In my case, I have a table called UnitOccupancy with a UnitID column that points to the primary key UnitID of the Units table. In code, if I want to access UnitCode in Units, from UnitOccupancy, I write Units.UnitCode. But I can't set the DataTextField of a DropDownList control to Units.UnitCode. It only seems to accept column references in the base table.

For example, this does not work:

< asp:DropDownList ID="unitDropdown" runat="server" DataSourceID="ldsUnitOccupancy"
                            DataValueField="UnitID" DataTextField="UnitCode" SelectedValue='<%# Bind("UnitID") %>' >
                        < / asp:DropDownList>

You might think I should create a LinqDataSource that points to the Units table, but here I hit another problem. I need to restrict the units to those where the UnitOccupancy table fulfills some criteria. In SQL I want to do this:

select u.UnitID, u.UnitCode
from Units u
join UnitOccupancy uo on u.UnitID=uo.UnitID
where uo.BranchID=@BranchID

If my LinqDataSource points to UnitOccupancy the Where clause works, but I can't get UnitCode. If my LinqDataSource points to Units I can get UnitCode, but I don't know how to make the Where clause work.

I have also tried programmatically setting the DataSource of the DDL to a stored procedure (created as a method in the .dbml) that runs the above SQL. However I can't seem to get this approach to work if the Bind function is used in the DDL (which is essential for the DDL to automatically update the UnitID value of my record).

Any suggestions?

 
New Post
2/17/2009 8:41 PM
 

 A really big example, but there are several lookup tables with dropdown lists using standard DNN module controllers...

<asp:GridView ID="GridComponent" runat="server" 
    AllowPaging="True" AutoGenerateColumns="False"
    DataKeyNames="componentId"
    DataSourceID="ComponentDataSource"
    Enableview_state="False">
    <Columns>
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"  />
 <asp:TemplateField HeaderText="ComponentTypeName">
    <ItemTemplate>
       <asp:Label id="lblComponentTypeName" runat="server"
           Text='<%# Eval("ComponentTypeName") %>'>
       </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
       <asp:DropDownList id="ddlComponentTypeName" runat="server" 
 DataSourceID="ComponentTypeDataSource"
           DataTextField="ComponentTypeName" DataValueField="ComponentTypeId"
           SelectedValue='<%# Bind("ComponentTypeId") %>'>
       </asp:DropDownList>
    </EditItemTemplate>
 </asp:TemplateField>
        <asp:BoundField DataField="ComponentName" HeaderText="ComponentName" SortExpression="ComponentName" Visible="True"  />
 <asp:TemplateField HeaderText="EnvironmentName">
    <ItemTemplate>
       <asp:Label id="lblEnvironmentName" runat="server"
           Text='<%# Eval("EnvironmentName") %>'>
       </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
       <asp:DropDownList id="ddlEnvironmentName" runat="server" 
 DataSourceID="EnvironmentDataSource"
           DataTextField="EnvironmentName" DataValueField="EnvironmentId"
           SelectedValue='<%# Bind("EnvironmentId") %>'>
       </asp:DropDownList>
    </EditItemTemplate>
 </asp:TemplateField>
 <asp:TemplateField HeaderText="VendorName">
    <ItemTemplate>
       <asp:Label id="lblVendorName" runat="server"
           Text='<%# Eval("VendorName") %>'>
       </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
       <asp:DropDownList id="ddlVendorName" runat="server" 
 DataSourceID="VendorDataSource"
           DataTextField="VendorName" DataValueField="VendorId"
           SelectedValue='<%# Bind("VendorId") %>'>
       </asp:DropDownList>
    </EditItemTemplate>
 </asp:TemplateField>
 <asp:TemplateField HeaderText="PlatformName">
    <ItemTemplate>
       <asp:Label id="lblPlatformName" runat="server"
           Text='<%# Eval("PlatformName") %>'>
       </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
       <asp:DropDownList id="ddlPlatformName" runat="server" 
 DataSourceID="PlatformDataSource"
           DataTextField="PlatformName" DataValueField="PlatformId"
           SelectedValue='<%# Bind("PlatformId") %>'>
       </asp:DropDownList>
    </EditItemTemplate>
 </asp:TemplateField>
        <asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" Visible="True"  />
        <asp:BoundField DataField="SerialNo" HeaderText="SerialNo" SortExpression="SerialNo" Visible="True"  />
        <asp:BoundField DataField="AssetNo" HeaderText="AssetNo" SortExpression="AssetNo" Visible="True"  />
        <asp:BoundField DataField="AssetTag" HeaderText="AssetTag" SortExpression="AssetTag" Visible="True"  />
        <asp:BoundField DataField="Purpose" HeaderText="Purpose" SortExpression="Purpose" Visible="True"  />
 <asp:TemplateField HeaderText="SoftwareName">
    <ItemTemplate>
       <asp:Label id="lblSoftwareName" runat="server"
           Text='<%# Eval("SoftwareName") %>'>
       </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
       <asp:DropDownList id="ddlSoftwareName" runat="server" 
 DataSourceID="SoftwareDataSource"
           DataTextField="SoftwareName" DataValueField="SoftwareId"
           SelectedValue='<%# Bind("OperatingSystemId") %>'
 AppendDataBoundItems="true">
           <asp:ListItem Text="None" Value="-1"></asp:ListItem>
       </asp:DropDownList>
    </EditItemTemplate>
 </asp:TemplateField>
        <asp:BoundField DataField="Processors" HeaderText="Processors" SortExpression="Processors" Visible="True"  />
        <asp:BoundField DataField="Cores" HeaderText="Cores" SortExpression="Cores" Visible="True"  />
        <asp:BoundField DataField="ProcessorType" HeaderText="ProcessorType" SortExpression="ProcessorType" Visible="True"  />
        <asp:BoundField DataField="ILOMVersion" HeaderText="ILOMVersion" SortExpression="ILOMVersion" Visible="True"  />
        <asp:BoundField DataField="FirmwareVersion" HeaderText="FirmwareVersion" SortExpression="FirmwareVersion" Visible="True"  />
        <asp:BoundField DataField="Memory" HeaderText="Memory" SortExpression="Memory" Visible="True"  />
        <asp:BoundField DataField="Disks" HeaderText="Disks" SortExpression="Disks" Visible="True"  />
        <asp:BoundField DataField="DiskSize" HeaderText="DiskSize" SortExpression="DiskSize" Visible="True"  />
        <asp:BoundField DataField="SubComponent" HeaderText="SubComponent" SortExpression="SubComponent" Visible="True"  />
 <asp:TemplateField HeaderText="ComponentName">
    <ItemTemplate>
       <asp:Label id="lblComponentName" runat="server"
           Text='<%# Eval("ComponentName") %>'>
       </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
       <asp:DropDownList id="ddlComponentName" runat="server" 
 DataSourceID="ComponentDataSource"
           DataTextField="ComponentName" DataValueField="ComponentId"
           SelectedValue='<%# Bind("ParentComponentId") %>'
 AppendDataBoundItems="true">
           <asp:ListItem Text="None" Value="-1"></asp:ListItem>
       </asp:DropDownList>
    </EditItemTemplate>
 </asp:TemplateField>
 <asp:TemplateField HeaderText="RackName">
    <ItemTemplate>
       <asp:Label id="lblRackName" runat="server"
           Text='<%# Eval("RackName") %>'>
       </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
       <asp:DropDownList id="ddlRackName" runat="server" 
 DataSourceID="RackDataSource"
           DataTextField="RackName" DataValueField="RackId"
           SelectedValue='<%# Bind("RackId") %>'>
       </asp:DropDownList>
    </EditItemTemplate>
 </asp:TemplateField>
        <asp:BoundField DataField="RackPosition" HeaderText="RackPosition" SortExpression="RackPosition" Visible="True"  />
        <asp:BoundField DataField="RackU" HeaderText="RackU" SortExpression="RackU" Visible="True"  />
        <asp:BoundField DataField="InServiceDate" HeaderText="InServiceDate" SortExpression="InServiceDate" Visible="True"  />
        <asp:BoundField DataField="InService" HeaderText="InService" SortExpression="InService" Visible="True"  />
        <asp:BoundField DataField="Decommissioned" HeaderText="Decommissioned" SortExpression="Decommissioned" Visible="True"  />
        <asp:BoundField DataField="DecommissionDate" HeaderText="DecommissionDate" SortExpression="DecommissionDate" Visible="True"  />
        <asp:BoundField DataField="PurchaseCost" HeaderText="PurchaseCost" SortExpression="PurchaseCost" Visible="True"  />
        <asp:BoundField DataField="MonthyAmortization" HeaderText="MonthyAmortization" SortExpression="MonthyAmortization" Visible="True"  />
        <asp:BoundField DataField="MonthlySMCCharge" HeaderText="MonthlySMCCharge" SortExpression="MonthlySMCCharge" Visible="True"  />
        <asp:BoundField DataField="EDSPONumber" HeaderText="EDSPONumber" SortExpression="EDSPONumber" Visible="True"  />
        <asp:BoundField DataField="CANNumber" HeaderText="CANNumber" SortExpression="CANNumber" Visible="True"  />
        <asp:BoundField DataField="BQProjCode" HeaderText="BQProjCode" SortExpression="BQProjCode" Visible="True"  />
        <asp:BoundField DataField="Version" HeaderText="Version" SortExpression="Version" Visible="True"  />
    </Columns>
    <EmptyDataTemplate>
        There are no Component Records
    </EmptyDataTemplate>
</asp:GridView>
<br  />
<asp:LinkButton ID="AddItemButton" runat="server" Enableview_state="False">Add Component</asp:LinkButton>
<br  /><br  />
<asp:formView ID="formComponent" runat="server" 
 DataKeyNames="componentId" 
 DataSourceID="ComponentDataSource"
    DefaultMode="Insert" Visible="False">
    <EditItemTemplate>
    </EditItemTemplate>
    <InsertItemTemplate>
 <Table>
 <tr><td colspan = "2">
 <asp:ValidationSummary
 HeaderText="The following fields have errors:"
 DisplayMode="BulletList"
 EnableClientScript="true"
 runat="server" />
 </td></tr>
        <tr><td></td>
 <td><asp:TextBox ID="txtPortalId" runat="server" Text='<%# Bind("PortalId") %>' Visible="False"></asp:TextBox></td>
 </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblComponentTypeId" runat="server" controlname="lblComponentTypeId" suffix=":"></dnn:label></td>
        <td class="Normal">
 <asp:DropDownList ID="drpComponentTypeId" runat="server" 
 DataSourceID="ComponentTypeDataSource"
                DataTextField="ComponentTypeName" 
             DataValueField="ComponentTypeId" 
                SelectedValue='<%# Bind("ComponentTypeId") %>'  />
 &nbsp;(<asp:Label ID="dspComponentTypeId" runat="server" Text='<%# Eval("ComponentTypeId") %>'  />)
 </td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblComponentName" runat="server" controlname="lblComponentName" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtComponentName" runat="server" Text='<%# Bind("ComponentName") %>' Enableview_state="False"></asp:TextBox><asp:requiredfieldvalidator id="reqComponentName" CssClass="NormalRed" runat="server" resourcekey="valComponentNameReq.ErrorMessage" ControlToValidate="txtComponentName" Display="Dynamic" ErrorMessage="Required Field."></asp:requiredfieldvalidator></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblEnvironmentId" runat="server" controlname="lblEnvironmentId" suffix=":"></dnn:label></td>
        <td class="Normal">
 <asp:DropDownList ID="drpEnvironmentId" runat="server" 
 DataSourceID="EnvironmentDataSource"
                DataTextField="EnvironmentName" 
             DataValueField="EnvironmentId" 
                SelectedValue='<%# Bind("EnvironmentId") %>'  />
 &nbsp;(<asp:Label ID="dspEnvironmentId" runat="server" Text='<%# Eval("EnvironmentId") %>'  />)
 </td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblVendorId" runat="server" controlname="lblVendorId" suffix=":"></dnn:label></td>
        <td class="Normal">
 <asp:DropDownList ID="drpVendorId" runat="server" 
 DataSourceID="VendorDataSource"
                DataTextField="VendorName" 
             DataValueField="VendorId" 
                SelectedValue='<%# Bind("VendorId") %>'  />
 &nbsp;(<asp:Label ID="dspVendorId" runat="server" Text='<%# Eval("VendorId") %>'  />)
 </td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblPlatformId" runat="server" controlname="lblPlatformId" suffix=":"></dnn:label></td>
        <td class="Normal">
 <asp:DropDownList ID="drpPlatformId" runat="server" 
 DataSourceID="PlatformDataSource"
                DataTextField="PlatformName" 
             DataValueField="PlatformId" 
                SelectedValue='<%# Bind("PlatformId") %>'  />
 &nbsp;(<asp:Label ID="dspPlatformId" runat="server" Text='<%# Eval("PlatformId") %>'  />)
 </td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblModel" runat="server" controlname="lblModel" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtModel" runat="server" Text='<%# Bind("Model") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblSerialNo" runat="server" controlname="lblSerialNo" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtSerialNo" runat="server" Text='<%# Bind("SerialNo") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblAssetNo" runat="server" controlname="lblAssetNo" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtAssetNo" runat="server" Text='<%# Bind("AssetNo") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblAssetTag" runat="server" controlname="lblAssetTag" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtAssetTag" runat="server" Text='<%# Bind("AssetTag") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblPurpose" runat="server" controlname="lblPurpose" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtPurpose" runat="server" Text='<%# Bind("Purpose") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblOperatingSystemId" runat="server" controlname="lblOperatingSystemId" suffix=":"></dnn:label></td>
        <td class="Normal">
 <asp:DropDownList ID="drpOperatingSystemId" runat="server" 
 DataSourceID="SoftwareDataSource"
                DataTextField="SoftwareName" 
             DataValueField="SoftwareId" 
                SelectedValue='<%# Bind("OperatingSystemId") %>'  />
 &nbsp;(<asp:Label ID="dspOperatingSystemId" runat="server" Text='<%# Eval("OperatingSystemId") %>'  />)
 </td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblProcessors" runat="server" controlname="lblProcessors" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtProcessors" runat="server" Text='<%# Bind("Processors") %>' Enableview_state="False"></asp:TextBox><asp:comparevalidator id="comProcessors" CssClass="NormalRed" runat="server" resourcekey="valProcessors.ErrorMessage" ControlToValidate="txtProcessors" Display="Dynamic" ErrorMessage="Not Integer" Type="Integer" Operator="DataTypeCheck"  /></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblCores" runat="server" controlname="lblCores" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtCores" runat="server" Text='<%# Bind("Cores") %>' Enableview_state="False"></asp:TextBox><asp:comparevalidator id="comCores" CssClass="NormalRed" runat="server" resourcekey="valCores.ErrorMessage" ControlToValidate="txtCores" Display="Dynamic" ErrorMessage="Not Integer" Type="Integer" Operator="DataTypeCheck"  /></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblProcessorType" runat="server" controlname="lblProcessorType" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtProcessorType" runat="server" Text='<%# Bind("ProcessorType") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblILOMVersion" runat="server" controlname="lblILOMVersion" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtILOMVersion" runat="server" Text='<%# Bind("ILOMVersion") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblFirmwareVersion" runat="server" controlname="lblFirmwareVersion" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtFirmwareVersion" runat="server" Text='<%# Bind("FirmwareVersion") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblMemory" runat="server" controlname="lblMemory" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtMemory" runat="server" Text='<%# Bind("Memory") %>' Enableview_state="False"></asp:TextBox><asp:comparevalidator id="comMemory" CssClass="NormalRed" runat="server" resourcekey="valMemory.ErrorMessage" ControlToValidate="txtMemory" Display="Dynamic" ErrorMessage="Not Integer" Type="Integer" Operator="DataTypeCheck"  /></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblDisks" runat="server" controlname="lblDisks" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtDisks" runat="server" Text='<%# Bind("Disks") %>' Enableview_state="False"></asp:TextBox><asp:comparevalidator id="comDisks" CssClass="NormalRed" runat="server" resourcekey="valDisks.ErrorMessage" ControlToValidate="txtDisks" Display="Dynamic" ErrorMessage="Not Integer" Type="Integer" Operator="DataTypeCheck"  /></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblDiskSize" runat="server" controlname="lblDiskSize" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtDiskSize" runat="server" Text='<%# Bind("DiskSize") %>' Enableview_state="False"></asp:TextBox><asp:comparevalidator id="comDiskSize" CssClass="NormalRed" runat="server" resourcekey="valDiskSize.ErrorMessage" ControlToValidate="txtDiskSize" Display="Dynamic" ErrorMessage="Not Integer" Type="Integer" Operator="DataTypeCheck"  /></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblSubComponent" runat="server" controlname="lblSubComponent" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:checkbox id="txtSubComponent" runat="server" Checked='<%# Bind("SubComponent") %>'  /></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblParentComponentId" runat="server" controlname="lblParentComponentId" suffix=":"></dnn:label></td>
        <td class="Normal">
 <asp:DropDownList ID="drpParentComponentId" runat="server" 
 DataSourceID="ComponentDataSource"
                DataTextField="ComponentName" 
             DataValueField="ComponentId" 
                SelectedValue='<%# Bind("ParentComponentId") %>'  />
 &nbsp;(<asp:Label ID="dspParentComponentId" runat="server" Text='<%# Eval("ParentComponentId") %>'  />)
 </td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblRackId" runat="server" controlname="lblRackId" suffix=":"></dnn:label></td>
        <td class="Normal">
 <asp:DropDownList ID="drpRackId" runat="server" 
 DataSourceID="RackDataSource"
                DataTextField="RackName" 
             DataValueField="RackId" 
                SelectedValue='<%# Bind("RackId") %>'  />
 &nbsp;(<asp:Label ID="dspRackId" runat="server" Text='<%# Eval("RackId") %>'  />)
 </td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblRackPosition" runat="server" controlname="lblRackPosition" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtRackPosition" runat="server" Text='<%# Bind("RackPosition") %>' Enableview_state="False"></asp:TextBox><asp:comparevalidator id="comRackPosition" CssClass="NormalRed" runat="server" resourcekey="valRackPosition.ErrorMessage" ControlToValidate="txtRackPosition" Display="Dynamic" ErrorMessage="Not Integer" Type="Integer" Operator="DataTypeCheck"  /></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblRackU" runat="server" controlname="lblRackU" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtRackU" runat="server" Text='<%# Bind("RackU") %>' Enableview_state="False"></asp:TextBox><asp:comparevalidator id="comRackU" CssClass="NormalRed" runat="server" resourcekey="valRackU.ErrorMessage" ControlToValidate="txtRackU" Display="Dynamic" ErrorMessage="Not Integer" Type="Integer" Operator="DataTypeCheck"  /></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblInServiceDate" runat="server" controlname="lblInServiceDate" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtInServiceDate" runat="server" Text='<%# Bind("InServiceDate") %>' Enableview_state="False"></asp:TextBox><asp:comparevalidator id="comInServiceDate" CssClass="NormalRed" runat="server" resourcekey="valInServiceDate.ErrorMessage" ControlToValidate="txtInServiceDate" Display="Dynamic" ErrorMessage="Not Date" Type="Date" Operator="DataTypeCheck"></asp:comparevalidator></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblInService" runat="server" controlname="lblInService" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:checkbox id="txtInService" runat="server" Checked='<%# Bind("InService") %>'  /></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblDecommissioned" runat="server" controlname="lblDecommissioned" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:checkbox id="txtDecommissioned" runat="server" Checked='<%# Bind("Decommissioned") %>'  /></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblDecommissionDate" runat="server" controlname="lblDecommissionDate" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtDecommissionDate" runat="server" Text='<%# Bind("DecommissionDate") %>' Enableview_state="False"></asp:TextBox><asp:comparevalidator id="comDecommissionDate" CssClass="NormalRed" runat="server" resourcekey="valDecommissionDate.ErrorMessage" ControlToValidate="txtDecommissionDate" Display="Dynamic" ErrorMessage="Not Date" Type="Date" Operator="DataTypeCheck"></asp:comparevalidator></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblPurchaseCost" runat="server" controlname="lblPurchaseCost" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtPurchaseCost" runat="server" Text='<%# Bind("PurchaseCost") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblMonthyAmortization" runat="server" controlname="lblMonthyAmortization" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtMonthyAmortization" runat="server" Text='<%# Bind("MonthyAmortization") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblMonthlySMCCharge" runat="server" controlname="lblMonthlySMCCharge" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtMonthlySMCCharge" runat="server" Text='<%# Bind("MonthlySMCCharge") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblEDSPONumber" runat="server" controlname="lblEDSPONumber" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtEDSPONumber" runat="server" Text='<%# Bind("EDSPONumber") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblCANNumber" runat="server" controlname="lblCANNumber" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtCANNumber" runat="server" Text='<%# Bind("CANNumber") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
        <tr>
        <td class="SubHead"><dnn:label id="lblBQProjCode" runat="server" controlname="lblBQProjCode" suffix=":"></dnn:label></td>
        <td class="Normal"><asp:TextBox ID="txtBQProjCode" runat="server" Text='<%# Bind("BQProjCode") %>' Enableview_state="False"></asp:TextBox></td>
        </tr>
       </table> 
         <p>
             <asp:LinkButton ID="InsertItemButton" runat="server" 
                 CausesValidation="True" CommandName="Insert"
                 Text="Insert" OnClick="InsertItemButton_Click">
             </asp:LinkButton>&nbsp;
             <asp:LinkButton ID="InsertCancelButton" runat="server" 
                 CausesValidation="False" CommandName="Cancel"
                 Text="Cancel" OnClick="InsertCancelButton_Click">
             </asp:LinkButton>
         </p>
     </InsertItemTemplate>
     <ItemTemplate>
     </ItemTemplate>
</asp:formView>
<asp:ObjectDataSource ID="ComponentDataSource" runat="server" 
    DataObjectTypeName="EDS.Modules.CapacityPlanning.ComponentInfo"
    DeleteMethod="DeleteComponent" 
    InsertMethod="AddComponent" 
    OldValuesParameterformatString="original_{0}"
    SelectMethod="ListComponents" 
    TypeName="EDS.Modules.CapacityPlanning.CapacityPlanningController"
    UpdateMethod="UpdateComponent"
 ConvertNullToDBNull="true">
    <SelectParameters>
        <asp:Parameter DefaultValue="00" Name="PortalId" Type="Int32"  />
    </SelectParameters>
    <InsertParameters>
 <asp:Parameter Name="ComponentId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="PortalId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="ComponentTypeId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="ComponentName" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="EnvironmentId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="VendorId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="PlatformId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Model" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="SerialNo" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="AssetNo" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="AssetTag" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Purpose" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="OperatingSystemId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Processors" Type="Int16" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Cores" Type="Int16" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="ProcessorType" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="ILOMVersion" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="FirmwareVersion" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Memory" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Disks" Type="Int16" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="DiskSize" Type="Int16" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="SubComponent" Type="Boolean" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="ParentComponentId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="RackId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="RackPosition" Type="Int16" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="RackU" Type="Int16" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="InServiceDate" Type="DateTime" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="InService" Type="Boolean" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Decommissioned" Type="Boolean" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="DecommissionDate" Type="DateTime" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="PurchaseCost" Type="decimal" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="MonthyAmortization" Type="decimal" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="MonthlySMCCharge" Type="decimal" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="EDSPONumber" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="CANNumber" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="BQProjCode" Type="String" ConvertEmptyStringToNull="true"  />
 </InsertParameters>
 <UpdateParameters>
 <asp:Parameter Name="ComponentId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="PortalId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="ComponentTypeId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="ComponentName" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="EnvironmentId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="VendorId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="PlatformId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Model" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="SerialNo" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="AssetNo" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="AssetTag" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Purpose" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="OperatingSystemId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Processors" Type="Int16" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Cores" Type="Int16" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="ProcessorType" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="ILOMVersion" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="FirmwareVersion" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Memory" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Disks" Type="Int16" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="DiskSize" Type="Int16" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="SubComponent" Type="Boolean" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="ParentComponentId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="RackId" Type="Int32" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="RackPosition" Type="Int16" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="RackU" Type="Int16" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="InServiceDate" Type="DateTime" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="InService" Type="Boolean" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="Decommissioned" Type="Boolean" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="DecommissionDate" Type="DateTime" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="PurchaseCost" Type="decimal" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="MonthyAmortization" Type="decimal" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="MonthlySMCCharge" Type="decimal" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="EDSPONumber" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="CANNumber" Type="String" ConvertEmptyStringToNull="true"  />
 <asp:Parameter Name="BQProjCode" Type="String" ConvertEmptyStringToNull="true"  />
 </UpdateParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ComponentTypeDataSource" runat="server" 
 DataObjectTypeName="EDS.Modules.CapacityPlanning.ComponentTypeInfo"
 TypeName="EDS.Modules.CapacityPlanning.CapacityPlanningController"
 SelectMethod="ListComponentTypes" 
 ConvertNullToDBNull="true">
    <SelectParameters>
        <asp:Parameter DefaultValue="00" Name="PortalId" Type="Int32"  />
    </SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="EnvironmentDataSource" runat="server" 
 DataObjectTypeName="EDS.Modules.CapacityPlanning.EnvironmentInfo"
 TypeName="EDS.Modules.CapacityPlanning.CapacityPlanningController"
 SelectMethod="ListEnvironments" 
 ConvertNullToDBNull="true">
    <SelectParameters>
        <asp:Parameter DefaultValue="00" Name="PortalId" Type="Int32"  />
    </SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="VendorDataSource" runat="server" 
 DataObjectTypeName="EDS.Modules.CapacityPlanning.VendorInfo"
 TypeName="EDS.Modules.CapacityPlanning.CapacityPlanningController"
 SelectMethod="ListVendors" 
 ConvertNullToDBNull="true">
    <SelectParameters>
        <asp:Parameter DefaultValue="00" Name="PortalId" Type="Int32"  />
    </SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="PlatformDataSource" runat="server" 
 DataObjectTypeName="EDS.Modules.CapacityPlanning.PlatformInfo"
 TypeName="EDS.Modules.CapacityPlanning.CapacityPlanningController"
 SelectMethod="ListPlatforms" 
 ConvertNullToDBNull="true">
    <SelectParameters>
        <asp:Parameter DefaultValue="00" Name="PortalId" Type="Int32"  />
    </SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="SoftwareDataSource" runat="server" 
 DataObjectTypeName="EDS.Modules.CapacityPlanning.SoftwareInfo"
 TypeName="EDS.Modules.CapacityPlanning.CapacityPlanningController"
 SelectMethod="ListSoftwares" 
 ConvertNullToDBNull="true">
    <SelectParameters>
        <asp:Parameter DefaultValue="00" Name="PortalId" Type="Int32"  />
    </SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="RackDataSource" runat="server" 
 DataObjectTypeName="EDS.Modules.CapacityPlanning.RackInfo"
 TypeName="EDS.Modules.CapacityPlanning.CapacityPlanningController"
 SelectMethod="ListRacks" 
 ConvertNullToDBNull="true">
    <SelectParameters>
        <asp:Parameter DefaultValue="00" Name="PortalId" Type="Int32"  />
    </SelectParameters>
</asp:ObjectDataSource>

 
New Post
2/19/2009 9:26 AM
 

Thanks.I actually figured out a simple way to do it. Just add a property for the column in the related table to a partial class for the base table, and return the usual LINQ expression for the related column, in my case Unit.UnitCode:

public partial class UnitOccupancy

{

public string UnitCode

{

get

{

return this.Unit.UnitCode;

}

}

}

Then you can reference this property in the drop down list like this:

< asp:DropDownList ID="unitDropdown" runat="server" DataSourceID="ldsUnitOccupancy"
                            DataValueField="UnitID" DataTextField="UnitCode" SelectedValue='<%# Bind("UnitID") %>' >
                        < / asp:DropDownList>

 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...LINQ to SQL - how to databind a dropdownlist to a table, but get DataTextField from related tableLINQ to SQL - how to databind a dropdownlist to a table, but get DataTextField from related table


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out