<asp:FormView ID="FormView1" runat="server" AllowPaging="True"
DataSourceID="SqlDataSource1" OnModeChanging="FormView1_ModeChanging">
<EditItemTemplate>
ID :
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
CpuName :
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
Status :
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</EditItemTemplate>
<EmptyDataTemplate>
There is no data.
</EmptyDataTemplate>
<ItemTemplate>
<table>
<tr>
<td align="right"><b>ID: </b></td>
<td><%# Eval("Id") %></td>
</tr>
<tr>
<td align="right"><b>CPUName:</b></td>
<td><%# Eval("cpuname") %></td>
</tr>
<tr>
<td align="right"><b>Status</b></td>
<td><%# Eval("status") %></td>
</tr>
</table>
<asp:LinkButton CommandName="Edit" runat="server">Edit</asp:LinkButton>
<asp:LinkButton CommandName="Insert" runat="server">Insert</asp:LinkButton>
</ItemTemplate>
<InsertItemTemplate>
<table>
<tr>
<td align="right"><b>ID: </b></td>
<td>
<asp:TextBox ID="txtFVID" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="right"><b>CPUName:</b></td>
<td>
<asp:TextBox ID="txtFVName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="right"><b>Status</b></td>
<td>
<asp:TextBox ID="txtFVStatus" runat="server"></asp:TextBox></td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
protected void FormView1_ModeChanging(object sender, FormViewModeEventArgs e)
{
if (e.NewMode == FormViewMode.Edit)
{
FormView1.ChangeMode(FormViewMode.Edit);
}
if (e.NewMode == FormViewMode.Insert)
{
FormView1.ChangeMode(FormViewMode.Insert);
}
}
我得到以下錯誤: - FormView'FormView1'必須處於插入模式才能插入新記錄。FormView不會在插入模式下輸入。爲什麼?
萬人迷....絕對眼罩。做得好!!! –
不客氣!我很高興這很有幫助。 – Kirill