troubleshooting Question

DetailsView and Entity Framework

Avatar of jgoodale
jgoodaleFlag for United States of America asked on
C#Visual Basic.NETMicrosoft Dynamics
4 Comments2 Solutions1225 ViewsLast Modified:
You can see from my code below that I have a detailsview and I'm inserting into a database but I have a couple issues with this. The entity returns a field named productTypeID but I want to assign a value to the field and have it saved to the database. The productTypeID is stored in a session variable but I don't know how to get it to bind and save to the database using the entity. Ideally the productTypeID would be a hidden field that is bound to the entity and saved when the insert is triggered.
<asp:DetailsView ID="createLableView" runat="server" AutoGenerateRows="False" CssClass="frmLabel" BorderStyle="None" GridLines="None"
                DefaultMode="Insert" DataSourceID="ShippingLabelDataSource" DataKeyNames="id"  CellPadding="3">
                <Fields>
                    <asp:TemplateField HeaderText="Name" SortExpression="PersonName">
                        <InsertItemTemplate>
                            <asp:TextBox ID="txtPersonName" runat="server"  Text='<%# Bind("PersonName") %>'></asp:TextBox>
                            <asp:requiredfieldvalidator id="CompanyNameRequiredValidator"
                                controltovalidate="txtPersonName"
                                display="Dynamic"
                                text="Please enter your name." 
                                CssClass="labelValidate"
                                runat="server"/>                                      
                        </InsertItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="CompanyName" HeaderText="Company Name" 
                        SortExpression="CompanyName" />
                    <asp:TemplateField HeaderText="Address" SortExpression="Address">
                        <InsertItemTemplate>
                            <asp:TextBox ID="txtAddress" runat="server"  Text='<%# Bind("Address") %>'></asp:TextBox>
                            <asp:requiredfieldvalidator id="AddressRequiredValidator"
                                controltovalidate="txtAddress"
                                display="Dynamic"
                                text="Please enter your address." 
                                CssClass="labelValidate"
                                runat="server"/>                                      
                        </InsertItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="City" SortExpression="City">
                        <InsertItemTemplate>
                            <asp:TextBox ID="txtCity" runat="server"  Text='<%# Bind("City") %>'></asp:TextBox>
                            <asp:requiredfieldvalidator id="CityRequiredValidator"
                                controltovalidate="txtCity"
                                display="Dynamic"
                                text="Please enter your city." 
                                CssClass="labelValidate"
                                runat="server"/>                                      
                        </InsertItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="State" SortExpression="StateOrProvinceCode">
                        <InsertItemTemplate>
                            <asp:TextBox ID="txtStateOrProvinceCode" runat="server"  Text='<%# Bind("StateOrProvinceCode") %>'></asp:TextBox>
                            <asp:requiredfieldvalidator id="StateOrProvinceCodeRequiredValidator"
                                controltovalidate="txtStateOrProvinceCode"
                                display="Dynamic"
                                text="Please enter your state." 
                                CssClass="labelValidate"
                                runat="server"/>                                      
                        </InsertItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Zip Code" SortExpression="PostalCode">
                        <InsertItemTemplate>
                            <asp:TextBox ID="txtPostalCode" runat="server"  Text='<%# Bind("PostalCode") %>'></asp:TextBox>
                            <asp:requiredfieldvalidator id="PostalCodeRequiredValidator"
                                controltovalidate="txtPostalCode"
                                display="Dynamic"
                                text="Please enter your zip code." 
                                CssClass="labelValidate"
                                runat="server"/>                                      
                        </InsertItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="PhoneNumber" HeaderText="Phone Number" 
                        SortExpression="PhoneNumber" />
                    <asp:CheckBoxField DataField="residential" HeaderText="Is Residential?" 
                        SortExpression="residential" />
      
                    <asp:BoundField DataField="productTypeID" HeaderText="productTypeID" 
                        SortExpression="productTypeID" />

                    <asp:CommandField ShowInsertButton="True" CausesValidation="true" InsertImageUrl="/images/getStarted.jpg" ButtonType="Image" />
                </Fields>
                <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
                <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
                
            </asp:DetailsView>

            <asp:EntityDataSource ID="ShippingLabelDataSource" runat="server" 
                ConnectionString="name=GreenEntities" 
                DefaultContainerName="GreenEntities" EnableFlattening="False" 
                EntitySetName="shippingLabels" EnableInsert="True">
            </asp:EntityDataSource>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros