How do "update" a field in the <EditItemTemplate> that has a null value in t

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • justice750
    New Member
    • Jan 2010
    • 2

    #1

    How do "update" a field in the <EditItemTemplate> that has a null value in t

    Hi All,

    I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field is not a null value. I am not using any code behind (C#) to bind the data or manipulate the data.

    I have read that when there is a null value in the database that there is no record in the "dataset". Can anyone show me how to bind a value in the form when there is a null value previously.

    Thanks,

    J



    ...
    Code:
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
        <meta name="description" content="" />
    </asp:Content>    
    
    <asp:Content ID="Content4" ContentPlaceHolderID="PageTitle" Runat="Server">
        <asp:TextBox ID="TextTitle" runat="server" BorderStyle="None" Font-Bold="True" 
            Font-Names="Arial" Font-Size="18px"></asp:TextBox>
    </asp:Content>    
    
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">    
        <div style="position:absolute; top:230px;left:600px;width:400px">
            <table cellpadding="0" cellspacing="0">
                <tr>
                    <td width="50px" align="right">
                        <asp:TextBox ID="RecordCounter" runat="server" BorderStyle="None" 
                            Font-Bold="True" Font-Names="Tahoma" Font-Size="9pt" ForeColor="#AB1414" 
                            Width="50px"></asp:TextBox>
                    </td>
                    <td style="Font-Family:Tahoma; font-size:12px; font-weight:bold; color:#000000;" 
                        align="left">Total Records
                    </td>
                </tr>
            </table>
        </div>
        
        <div style="width:1024px; text-align: justify; overflow:hidden; padding-top:0px">                   
        <asp:GridView   ID="DealershipGrid" 
                        runat="server" 
                        AllowPaging="True" 
                        AllowSorting="True" 
                        AutoGenerateColumns="False" 
                        CellPadding="2" 
                        DataKeyNames="Dealership_Id" 
                        DataSourceID="DealershipsDS" 
                        ForeColor="#333333" 
                        GridLines="None" 
                        Font-Names="Tahoma" 
                        Font-Size="9pt" 
                        Font-Bold="False" 
                        Width="1024px" PageSize="10">
                <PagerSettings Position="TopAndBottom" />
                <FooterStyle BackColor="#8b1111" Font-Bold="True" ForeColor="White" />
                <RowStyle BackColor="#FFFFFF" ForeColor="#333333" Font-Names="Tahoma" Font-Size="8pt" />
                    <Columns>
                        <asp:CommandField ShowSelectButton="True" />
                        <asp:BoundField 
                                DataField="Dealership_Id" 
                                HeaderText="ID" 
                                InsertVisible="False" 
                                ReadOnly="True" 
                                SortExpression="Dealership_Id"
                                HeaderStyle-Width="3%" 
                                ItemStyle-Width="3%" 
                                FooterStyle-Width="3%" >
                            <FooterStyle Width="3%"></FooterStyle>
                            <HeaderStyle Width="3%" HorizontalAlign="Left"></HeaderStyle>
                            <ItemStyle Width="3%"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField 
                                DataField="Dealership_Name" 
                                HeaderText="Dealership" 
                                SortExpression="Dealership_Name" 
                                HeaderStyle-Width="18%" 
                                ItemStyle-Width="18%" 
                                FooterStyle-Width="18%">
                            <FooterStyle Width="18%"></FooterStyle>     
                            <HeaderStyle Width="18%" HorizontalAlign="Left"></HeaderStyle>
                            <ItemStyle Width="18%"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField 
                                DataField="Dealership_BranchName" 
                                HeaderText="Branch" 
                                SortExpression="Dealership_BranchName" 
                                HeaderStyle-Width="18%" 
                                ItemStyle-Width="18%" 
                                FooterStyle-Width="18%">
                            <FooterStyle Width="18%"></FooterStyle>
                            <HeaderStyle Width="18%" HorizontalAlign="Left"></HeaderStyle>
                            <ItemStyle Width="18%"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField 
                                DataField="Dealership_Phone1" 
                                HeaderText="Phone" 
                                SortExpression="Dealership_Phone1" 
                                HeaderStyle-Width="9%" 
                                ItemStyle-Width="9%" 
                                FooterStyle-Width="9%" >
                            <FooterStyle Width="9%"></FooterStyle>
                            <HeaderStyle Width="9%" HorizontalAlign="Left"></HeaderStyle>
                            <ItemStyle Width="9%"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField 
                                DataField="Dealership_Email1" 
                                HeaderText="Email" 
                                SortExpression="Dealership_Email1" 
                                HeaderStyle-Width="37%" 
                                ItemStyle-Width="37%" 
                                FooterStyle-Width="37%">
                            <FooterStyle Width="37%"></FooterStyle>
                            <HeaderStyle Width="37%" HorizontalAlign="Left"></HeaderStyle>
                            <ItemStyle Width="37%"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField 
                                DataField="Dealership_State" 
                                HeaderText="State" 
                                SortExpression="Dealership_State" 
                                HeaderStyle-Width="5%" 
                                ItemStyle-Width="5%" 
                                FooterStyle-Width="5%" >
                            <FooterStyle Width="5%"></FooterStyle>
                            <HeaderStyle Width="5%" HorizontalAlign="Left"></HeaderStyle>
                            <ItemStyle Width="5%"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField 
                                DataField="Dealership_ZipCode" 
                                HeaderText="Zip Code" 
                                SortExpression="Dealership_ZipCode" 
                                HeaderStyle-Width="6%" 
                                ItemStyle-Width="6%" 
                                FooterStyle-Width="6%" >
                            <FooterStyle Width="6%"></FooterStyle>
                            <HeaderStyle Width="6%" HorizontalAlign="Left"></HeaderStyle>
                            <ItemStyle Width="6%"></ItemStyle>
                        </asp:BoundField>
                    </Columns>
                        <PagerStyle BackColor="White" ForeColor="Maroon" HorizontalAlign="Right" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="False" ForeColor="#333333"  />
                        <HeaderStyle BackColor="#AB1414" Font-Bold="True" ForeColor="White" Font-Names="Tahoma" Font-Size="9pt" HorizontalAlign="Left" />
                        <EditRowStyle BackColor="#999999" ForeColor="Black" />
                        <AlternatingRowStyle BackColor="Silver" ForeColor="Black" />
                </asp:GridView>                    
    
       <asp:SqlDataSource ID="DealershipsDS" runat="server" 
                 
    
            ConnectionString="<%$ ConnectionStrings:driveaway2day2 %>" 
            SelectCommand="SELECT [Dealership_Id], [Dealership_Name], [Dealership_BranchName], [Dealership_Phone1], [Dealership_Email1], [Dealership_State], [Dealership_ZipCode] FROM [CAR_Dealership] ORDER BY [Dealership_Name]"  EnableViewState="False" OnSelected="DealershipsDS_Selected" >
        </asp:SqlDataSource>                                                          
            
    </div>
    <div>
            <asp:FormView 
                ID="DealershipFormView" 
                runat="server" 
                CellPadding="0" 
                ForeColor="#333333"
                DataKeyNames="Dealership_Id" 
                DataSourceID="DealershipsDetailDS" 
                AllowPaging="true" 
                Width="1024px" 
                BackColor="Black" 
                Font-Names="Tahoma" 
                Font-Size="8pt">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <ItemTemplate>
                <table border="0" width="1024px">
                    <tr>
                    <td height="20px" colspan="4" style="padding-top:0px;">&nbsp; </td>
                    </tr>
                    <tr>
                    <td colspan="4" style="padding-left:3px;height:20px; background-color:#E2DED6; font-family: Tahoma; font-size:12px; color:#000000; font-weight:bold; width:1024px;">Dealership Details</td>
                    </tr>
                    <tr>
                        <td>
                            <table width="800px">
                                <tr>
                                    <td colspan="4" style="padding-top:5px;height:5px;">&nbsp;</td>        
                                </tr>
                                <tr>                   
                                    <td style="padding-top:5px;" width="100px">Dealership ID</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_Id")%></td>
                                    <td style="padding-top:5px;" width="100px">Email 1</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_Email1")%></td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Dealership</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_Name")%></td>
                                    <td style="padding-top:5px;" width="100px">Email 2</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_Email2")%></td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Branch Name</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_BranchName")%></td>
                                    <td style="padding-top:5px;" width="100px">Email 3</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_Email3")%></td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Phone 1</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_Phone1")%></td>
                                    <td style="padding-top:5px;" width="100px">Address</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_Address")%></td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Phone 2</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_Phone2")%></td>
                                    <td style="padding-top:5px;" width="100px">City</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_City")%></td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Phone 3</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_Phone3")%></td>
                                    <td style="padding-top:5px;" width="100px">State</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_State")%></td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Fax</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_Fax")%></td>
                                    <td style="padding-top:5px;" width="100px">Zip Code</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_ZipCode")%></td>
                                </tr>
                                <tr>
                                    <td colspan="4" style="padding-top:5px;height:5px;">&nbsp;</td>        
                                </tr>
                            </tr>
                        </table>
                    </td>
                   
                <tr>
                     <td colspan="4" style="padding-top:5px;height:15px; background-color:#E2DED6;">&nbsp;</td>              
                </tr>
                <tr>
                     <td colspan="4" style="padding-top:5px;height:15px;">&nbsp;</td>               
                </tr>
                
                <tr>
                    <td colspan="2" style="padding-top:5px;">
                        <asp:Button ID="btnEdit" runat="Server" CommandName="Edit" Text="Edit" Font-Names="Tahoma" Font-Size="10px" />
                        <asp:Button ID="btnInsert" runat="Server" CommandName="New" Text="New" Font-Names="tahoma" Font-Size="10px" />
                        <asp:Button ID="btnDelete" runat="Server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure to Delete?');" Font-Size="10px" Font-Names="tahoma" />
                    </td>
                </tr>
            </table>
         </ItemTemplate>
         
            <EditItemTemplate>
                <table border="0" width="1024px" style="padding-top:0px;">
                    <tr>
                        <td height="20px" colspan="4" style="padding-top:0px;">&nbsp; </td>
                    </tr>
                    <tr>
                    <td colspan="4" style="padding-left:3px;height:20px; background-color:#E2DED6; font-family: Tahoma; font-size:12px; color:#000000; font-weight:bold; width:1024px;">Dealership Details</td>
                    </tr>
                    <tr>
                        <td>
                            <table width="800px">
                                <tr>
                                    <td colspan="4" style="padding-top:5px;height:5px;">&nbsp;</td>        
                                </tr>
                                <tr>                   
                                    <td style="padding-top:5px;" width="100px">Dealership ID</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_Id")%></td>
                                    <td style="padding-top:5px;" width="100px">Email 1</td>
                                    <td style="padding-top:5px;" width="300px">
    		                            <asp:TextBox ID="TextBox1" runat="Server" Text='<%# Bind("Dealership_Email1")%>'>
    		                            </asp:TextBox>
    		                        </td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Dealership</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox2" runat="Server" Text='<%# Bind("Dealership_Name")%>'>
                                        </asp:TextBox></td>
                                    <td style="padding-top:5px;" width="100px">Email 2</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox3" runat="Server" Text='<%# Bind("Dealership_Email2")%>'>
                                        </asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Branch Name</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox  ID="TextBox4" runat="Server" Text='<%# Bind("Dealership_BranchName")%>'>
                                        </asp:TextBox>
                                    </td>
                                    <td style="padding-top:5px;" width="100px">Email 3</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox5"  runat="Server" Text='<%# Bind("Dealership_Email3")%>'>
                                        </asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Phone 1</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox6" runat="Server" Text='<%# Bind("Dealership_Phone1")%>'>
                                        </asp:TextBox>
                                    </td>
                                    <td style="padding-top:5px;" width="100px">Address</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox7" runat="Server" Text='<%# Bind("Dealership_Address")%>'>
                                        </asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Phone 2</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox8" runat="Server" Text='<%# Bind("Dealership_Phone2")%>'>
                                        </asp:TextBox>
                                    </td>
                                    <td style="padding-top:5px;" width="100px">City</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox9" runat="Server" Text='<%# Bind("Dealership_City")%>'>
                                        </asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Phone 3</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox10" runat="Server" Text='<%# Bind("Dealership_Phone3")%>'>
                                        </asp:TextBox>
                                    </td>
                                    <td style="padding-top:5px;" width="100px">State</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:DropDownList ID="myDropDownList" runat="server"   
                                            AppendDataBoundItems="True"  
                                            DataSourceID="StatesDS"   
                                            DataValueField="Dealership_State" 
                                            DataTextField="name"  
                                            SelectedValue='<%#Bind("Dealership_State") %>'>  
                                            <asp:ListItem Value="">Select a State...
                                            </asp:ListItem>  
                                        </asp:DropDownList>  
                                        <asp:XmlDataSource ID="StatesDS" runat="server" DataFile="~/Ddl/States.xml">
                                        </asp:XmlDataSource>                         
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Fax</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox12" runat="Server" Text='<%# Bind("Dealership_Fax")%>'>
                                        </asp:TextBox>
                                    </td>
                                    <td style="padding-top:5px;" width="100px">Zip Code</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox13" runat="Server" Text='<%# Bind("Dealership_ZipCode")%>'>
                                        </asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="4" style="padding-top:5px;height:5px;">&nbsp;</td>        
                                </tr>                        
                            </tr>
                        </table>
                    </td>
                   
                <tr>
                     <td colspan="4" style="padding-top:5px;height:15px; background-color:#E2DED6;">&nbsp;</td>               
                </tr>
                <tr>
                     <td colspan="4" style="padding-top:5px;height:15px;">&nbsp;</td>                
                </tr>
                 <asp:RequiredFieldValidator ID="req1" runat="Server" ControlToValidate="TextBox1" ErrorMessage="Email 1 is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="Server" ControlToValidate="TextBox2" ErrorMessage="Dealership is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="Server" ControlToValidate="TextBox6" ErrorMessage="Phone 1 is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="Server" ControlToValidate="TextBox7" ErrorMessage="Address is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="Server" ControlToValidate="TextBox9" ErrorMessage="City is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="Server" ControlToValidate="TextBox13" ErrorMessage="Zip Code is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                     <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="Server" ControlToValidate="TextBox4" ErrorMessage="Branch/Location is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="Server" ControlToValidate="myDropDownList" ErrorMessage="State is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                <tr>
                    <td colspan="2" style="padding-top:5px;">            
                            <asp:Button ID="btnUpdate" runat="Server" CommandName="Update" Text="Update" Font-Names="tahoma" Font-Size="10px" />
                            <asp:Button ID="Button1" runat="Server" CommandName="Cancel" Text="Cancel" CausesValidation="False" Font-Names="tahoma" Font-Size="10px" />
                    </td>
                </tr>
                <asp:ValidationSummary ID="ValidationSummary" runat="Server" ShowMessageBox="true" />
            </table>
       
         </EditItemTemplate>     
         
     <InsertItemTemplate>
                 <table border="0" width="1024px" style="padding-top:0px;">
                    <tr>
                        <td height="20px" colspan="4" style="padding-top:0px;">&nbsp; </td>
                    </tr>
                    <tr>
                    <td colspan="4" style="padding-left:3px;height:20px; background-color:#E2DED6; font-family: Tahoma; font-size:12px; color:#000000; font-weight:bold; width:1024px;">Dealership Details</td>
                    </tr>
                    <tr>
                        <td>
                            <table width="800px">
                                <tr>
                                    <td colspan="4" style="padding-top:5px;height:5px;">&nbsp;</td>        
                                </tr>                        
                                <tr>                   
                                    <td style="padding-top:5px;" width="100px">Dealership ID</td>
                                    <td style="padding-top:5px;" width="300px"><%# Eval("Dealership_Id")%></td>
                                    <td style="padding-top:5px;" width="100px">Email 1</td>
                                    <td style="padding-top:5px;" width="300px">
    		                            <asp:TextBox ID="TextBox1" runat="Server" Text='<%# Bind("Dealership_Email1")%>'>
    		                            </asp:TextBox>
    		                        </td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Dealership</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox2" runat="Server" Text='<%# Bind("Dealership_Name")%>'>
                                        </asp:TextBox></td>
                                    <td style="padding-top:5px;" width="100px">Email 2</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox3" runat="Server" Text='<%# Bind("Dealership_Email2")%>'>
                                        </asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Branch Name</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox4" runat="Server" Text='<%# Bind("Dealership_BranchName")%>'>
                                        </asp:TextBox>
                                    </td>
                                    <td style="padding-top:5px;" width="100px">Email 3</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox5" runat="Server" Text='<%# Bind("Dealership_Email3")%>'>
                                        </asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Phone 1</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox6" runat="Server" Text='<%# Bind("Dealership_Phone1")%>'>
                                        </asp:TextBox>
                                    </td>
                                    <td style="padding-top:5px;" width="100px">Address</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox7" runat="Server" Text='<%# Bind("Dealership_Address")%>'>
                                        </asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Phone 2</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox8" runat="Server" Text='<%# Bind("Dealership_Phone2")%>'>
                                        </asp:TextBox>
                                    </td>
                                    <td style="padding-top:5px;" width="100px">City</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox9" runat="Server" Text='<%# Bind("Dealership_City")%>'>
                                        </asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Phone 3</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox10" runat="Server" Text='<%# Bind("Dealership_Phone3")%>'>
                                        </asp:TextBox>
                                    </td>
                                    <td style="padding-top:5px;" width="100px">State</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:DropDownList ID="myDropDownList" runat="server"   
                                            AppendDataBoundItems="True"  
                                            DataSourceID="StatesDS"   
                                            DataValueField="Dealership_State" 
                                            DataTextField="name"  
                                            SelectedValue='<%#Bind("Dealership_State") %>'>  
                                            <asp:ListItem Value="">Select a State...
                                            </asp:ListItem>  
                                        </asp:DropDownList>  
                                        <asp:XmlDataSource ID="StatesDS" runat="server" DataFile="~/Ddl/States.xml">
                                        </asp:XmlDataSource>                         
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding-top:5px;" width="100px">Fax</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox12" runat="Server" Text='<%# Bind("Dealership_Fax")%>'>
                                        </asp:TextBox>
                                    </td>
                                    <td style="padding-top:5px;" width="100px">Zip Code</td>
                                    <td style="padding-top:5px;" width="300px">
                                        <asp:TextBox ID="TextBox13" runat="Server" Text='<%# Bind("Dealership_ZipCode")%>'>
                                        </asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="4" style="padding-top:5px;height:5px;">&nbsp;</td>        
                                </tr>                            
                            </tr>
                        </table>
                    </td>
                   
                <tr>
                     <td colspan="4" style="padding-top:5px;height:15px; background-color:#E2DED6;">&nbsp;</td>               
                </tr>
                <tr>
                     <td colspan="4" style="padding-top:5px;height:15px;">&nbsp;</td>                
                </tr>
                 <asp:RequiredFieldValidator ID="req1" runat="Server" ControlToValidate="TextBox1" ErrorMessage="Email 1 is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="Server" ControlToValidate="TextBox2" ErrorMessage="Dealership is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="Server" ControlToValidate="TextBox6" ErrorMessage="Phone 1 is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="Server" ControlToValidate="TextBox7" ErrorMessage="Address is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="Server" ControlToValidate="TextBox9" ErrorMessage="City is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="Server" ControlToValidate="TextBox13" ErrorMessage="Zip Code is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                     <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="Server" ControlToValidate="TextBox4" ErrorMessage="Branch/Location is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="Server" ControlToValidate="myDropDownList" ErrorMessage="State is Required" Text="Enter Correct Information.">
                    </asp:RequiredFieldValidator>
                    
                    
                <tr>
                    <td colspan="2" style="padding-top:5px;">
                         <asp:Button ID="btnSave" runat="Server" CommandName="insert" Text="Insert" Font-Names="tahoma" Font-Size="10px" />
                            <asp:Button ID="Button1" runat="Server" CommandName="Cancel" Text="Cancel" CausesValidation="False" Font-Names="tahoma" Font-Size="10px" />
    
    
                    </td>
                </tr>
            <asp:ValidationSummary ID="ValidationSummary" runat="Server" ShowMessageBox="true" />
            </table>
         </InsertItemTemplate>   
         
         
        </asp:FormView>
    <asp:SqlDataSource ID="DealershipsDetailDS" runat="server" 
            ConnectionString="<%$ ConnectionStrings:drivetime %>" 
            
            SelectCommand="SELECT [Dealership_Id], [Dealership_Name], [Dealership_BranchName], [Dealership_Phone1], [Dealership_Phone2], [Dealership_Phone3], [Dealership_Fax], [Dealership_Email1], [Dealership_Email2], [Dealership_Email3], [Dealership_Address], [Dealership_City], [Dealership_State], [Dealership_ZipCode] FROM [CAR_Dealership] WHERE ([Dealership_Id] = @Dealership_Id)" 
            ConflictDetection="CompareAllValues" 
            DeleteCommand="DELETE FROM [CAR_Dealership] WHERE [Dealership_Id] = @original_Dealership_Id AND [Dealership_Name] = @original_Dealership_Name AND [Dealership_BranchName] = @original_Dealership_BranchName AND [Dealership_Phone1] = @original_Dealership_Phone1 AND [Dealership_Phone2] = @original_Dealership_Phone2 AND [Dealership_Phone3] = @original_Dealership_Phone3 AND [Dealership_Fax] = @original_Dealership_Fax AND [Dealership_Email1] = @original_Dealership_Email1 AND [Dealership_Email2] = @original_Dealership_Email2 AND [Dealership_Email3] = @original_Dealership_Email3 AND [Dealership_Address] = @original_Dealership_Address AND [Dealership_City] = @original_Dealership_City AND [Dealership_State] = @original_Dealership_State AND [Dealership_ZipCode] = @original_Dealership_ZipCode" 
            InsertCommand="INSERT INTO [CAR_Dealership] ([Dealership_Name], [Dealership_BranchName], [Dealership_Phone1], [Dealership_Phone2], [Dealership_Phone3], [Dealership_Fax], [Dealership_Email1], [Dealership_Email2], [Dealership_Email3], [Dealership_Address], [Dealership_City], [Dealership_State], [Dealership_ZipCode]) VALUES (@Dealership_Name, @Dealership_BranchName, @Dealership_Phone1, @Dealership_Phone2, @Dealership_Phone3, @Dealership_Fax, @Dealership_Email1, @Dealership_Email2, @Dealership_Email3, @Dealership_Address, @Dealership_City, @Dealership_State, @Dealership_ZipCode)" 
            OldValuesParameterFormatString="original_{0}"      
            UpdateCommand="UPDATE [CAR_Dealership] SET [Dealership_Name] = @Dealership_Name, [Dealership_BranchName] = @Dealership_BranchName, [Dealership_Phone1] = @Dealership_Phone1, [Dealership_Phone2] = @Dealership_Phone2, [Dealership_Phone3] = @Dealership_Phone3, [Dealership_Fax] = @Dealership_Fax, [Dealership_Email1] = @Dealership_Email1, [Dealership_Email2] = @Dealership_Email2, [Dealership_Email3] = @Dealership_Email3, [Dealership_Address] = @Dealership_Address, [Dealership_City] = @Dealership_City, [Dealership_State] = @Dealership_State, [Dealership_ZipCode] = @Dealership_ZipCode WHERE [Dealership_Id] = @original_Dealership_Id AND [Dealership_Name] = @original_Dealership_Name AND [Dealership_BranchName] = @original_Dealership_BranchName AND [Dealership_Phone1] = @original_Dealership_Phone1 AND [Dealership_Phone2] = @original_Dealership_Phone2 AND [Dealership_Phone3] = @original_Dealership_Phone3 AND [Dealership_Fax] = @original_Dealership_Fax AND [Dealership_Email1] = @original_Dealership_Email1 AND [Dealership_Email2] = @original_Dealership_Email2 AND [Dealership_Email3] = @original_Dealership_Email3 AND [Dealership_Address] = @original_Dealership_Address AND [Dealership_City] = @original_Dealership_City AND [Dealership_State] = @original_Dealership_State AND [Dealership_ZipCode] = @original_Dealership_ZipCode">
        <SelectParameters>
            <asp:ControlParameter ControlID="DealershipGrid" Name="Dealership_Id" 
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="original_Dealership_Id" Type="Int32" />
            <asp:Parameter Name="original_Dealership_Name" Type="String" />
            <asp:Parameter Name="original_Dealership_BranchName" Type="String" />
            <asp:Parameter Name="original_Dealership_Phone1" Type="String" />
            <asp:Parameter Name="original_Dealership_Phone2" Type="String" />
            <asp:Parameter Name="original_Dealership_Phone3" Type="String" />
            <asp:Parameter Name="original_Dealership_Fax" Type="String" />
            <asp:Parameter Name="original_Dealership_Email1" Type="String" />
            <asp:Parameter Name="original_Dealership_Email2" Type="String" />
            <asp:Parameter Name="original_Dealership_Email3" Type="String" />
            <asp:Parameter Name="original_Dealership_Address" Type="String" />
            <asp:Parameter Name="original_Dealership_City" Type="String" />
            <asp:Parameter Name="original_Dealership_State" Type="String" />
            <asp:Parameter Name="original_Dealership_ZipCode" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="Dealership_Name" Type="String" />
            <asp:Parameter Name="Dealership_BranchName" Type="String" />
            <asp:Parameter Name="Dealership_Phone1" Type="String" />
            <asp:Parameter Name="Dealership_Phone2" Type="String" />
            <asp:Parameter Name="Dealership_Phone3" Type="String" />
            <asp:Parameter Name="Dealership_Fax" Type="String" />
            <asp:Parameter Name="Dealership_Email1" Type="String" />
            <asp:Parameter Name="Dealership_Email2" Type="String" />
            <asp:Parameter Name="Dealership_Email3" Type="String" />
            <asp:Parameter Name="Dealership_Address" Type="String" />
            <asp:Parameter Name="Dealership_City" Type="String" />
            <asp:Parameter Name="Dealership_State" Type="String" />
            <asp:Parameter Name="Dealership_ZipCode" Type="String" />
            <asp:Parameter Name="original_Dealership_Id" Type="Int32" />
            <asp:Parameter Name="original_Dealership_Name" Type="String" />
            <asp:Parameter Name="original_Dealership_BranchName" Type="String" />
            <asp:Parameter Name="original_Dealership_Phone1" Type="String" />
            <asp:Parameter Name="original_Dealership_Phone2" Type="String" />
            <asp:Parameter Name="original_Dealership_Phone3" Type="String" />
            <asp:Parameter Name="original_Dealership_Fax" Type="String" />
            <asp:Parameter Name="original_Dealership_Email1" Type="String" />
            <asp:Parameter Name="original_Dealership_Email2" Type="String" />
            <asp:Parameter Name="original_Dealership_Email3" Type="String" />
            <asp:Parameter Name="original_Dealership_Address" Type="String" />
            <asp:Parameter Name="original_Dealership_City" Type="String" />
            <asp:Parameter Name="original_Dealership_State" Type="String" />
            <asp:Parameter Name="original_Dealership_ZipCode" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="Dealership_Name" Type="String" />
            <asp:Parameter Name="Dealership_BranchName" Type="String" />
            <asp:Parameter Name="Dealership_Phone1" Type="String" />
            <asp:Parameter Name="Dealership_Phone2" Type="String" />
            <asp:Parameter Name="Dealership_Phone3" Type="String" />
            <asp:Parameter Name="Dealership_Fax" Type="String" />
            <asp:Parameter Name="Dealership_Email1" Type="String" />
            <asp:Parameter Name="Dealership_Email2" Type="String" />
            <asp:Parameter Name="Dealership_Email3" Type="String" />
            <asp:Parameter Name="Dealership_Address" Type="String" />
            <asp:Parameter Name="Dealership_City" Type="String" />
            <asp:Parameter Name="Dealership_State" Type="String" />
            <asp:Parameter Name="Dealership_ZipCode" Type="String" />
        </InsertParameters>
        </asp:SqlDataSource>
    
    </div>             
                                            
    </asp:Content>

    ...
    Last edited by Frinavale; Jan 12 '10, 01:55 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Hi J,

    In the future could you please only post the code that pertains to your question. That is a lot of code to ask people to look over. Also, in the future, please post your code in code tags.

    Anyways, I've never used a FormView before and I don't have much experience with the SqlDataSource; however, it sounds like you've designed your database in such a way that nulls aren't allowed. In this case you must provide a value for the fields that cannot be set to null or you have to change your database to allow nulls to be entered (but in a lot of cases it doesn't make sense to do this because the database design requires it)

    So, I recommend using things like the Validator controls to make sure that the user has entered something. You could also consider setting default values to help the user along.

    -Frinny

    Comment

    • justice750
      New Member
      • Jan 2010
      • 2

      #3
      Frinny,

      I will do all of the above. Thanks or your response. Nulls are allowed the db. How do you set default values for textboxes that also have bind.



      Thanks,

      J

      Code:
      <asp:TextBox class="aclDetTxt" ID="TextBox9" runat="Server" Text='<%# Bind("Dealership_City")%>'>
                                          </asp:TextBox>

      Comment

      • mzmishra
        Recognized Expert Contributor
        • Aug 2007
        • 390

        #4
        This article may help you
        http:// forums.asp.net/t/1064910.aspx

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Ahh, I think you'd be interested in looking at creating an EmptyDataTempla te for rows that contain not data.

          -Frinny

          Comment

          Working...