我正在使用 FormView 控件。这允许我更新数据库中的记录。但是,当数据库字段为空时,我无法更新表单上的字段。当字段不是空值时,它可以正常工作。我没有使用 (C#) 后面的任何代码来绑定数据或操作数据。
我已经读过,当数据库中有空值时,“数据集”中没有记录。当以前有空值时,谁能告诉我如何在表单中绑定一个值。
谢谢,
Ĵ
...
总记录
<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>
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>
经销商详情
经销商 ID <%# Eval("Dealership_Id")%> 电子邮件 1 <%# Eval("Dealership_Email1")%> 经销商 <%# Eval("Dealership_Name")%> 电子邮件 2 <%# Eval("Dealership_Email2")% > 分行名称 <%# Eval("Dealership_BranchName")%> 电子邮件 3 <%# Eval("Dealership_Email3")%>电话 1 <%# Eval("Dealership_Phone1")%> 地址 <%# Eval("Dealership_Address")%> 电话 2 <%# Eval("Dealership_Phone2")%> 城市 <%# Eval("Dealership_City")%>电话 3 <%# Eval("Dealership_Phone3")%> 状态 <%# Eval("Dealership_State")%> 传真 <%# Eval("Dealership_Fax")%> 邮政编码 <%# Eval("Dealership_ZipCode")%>
<tr>
<td colspan="4" style="padding-top:5px;height:15px; background-color:#E2DED6;"> </td>
</tr>
<tr>
<td colspan="4" style="padding-top:5px;height:15px;"> </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;"> </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;"> </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 class="aclDetTxt" 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 class="aclDetTxt" 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 class="aclDetTxt" 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 class="aclDetTxt" 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 class="aclDetTxt" 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 class="aclDetTxt" 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 class="aclDetTxt" 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 class="aclDetTxt" 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 class="aclDetTxt" 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 class="aclDetTxt" 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 class="aclDetDD" 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 class="aclDetTxt" 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 class="aclDetTxt" ID="TextBox13" runat="Server" Text='<%# Bind("Dealership_ZipCode")%>'>
</asp:TextBox>
</td>
</tr>
<tr>
<td colspan="4" style="padding-top:5px;height:5px;"> </td>
</tr>
</tr>
</table>
</td>
<tr>
<td colspan="4" style="padding-top:5px;height:15px; background-color:#E2DED6;"> </td>
</tr>
<tr>
<td colspan="4" style="padding-top:5px;height:15px;"> </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>
经销商详情
经销商 ID <%# Eval("Dealership_Id")%> 电子邮件 1 '> 经销商 '> 电子邮件 2 '>分行名称 '> 电子邮件 3 '> 电话 1 '>地址 '> 电话 2 '> 城市 '>电话 3 '> 状态