sly*_*dan 2 .net c# asp.net formview
<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);
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误: - FormView'FormView1'必须处于插入模式才能插入新记录.
加
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New" Text="New" />
Run Code Online (Sandbox Code Playgroud)
进入你的<ItemTemplate>.
移动你的
<asp:LinkButton CommandName="Insert" runat="server">Insert</asp:LinkButton>
</ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
到<InsertItemTemplate>它所属的地方.
| 归档时间: |
|
| 查看次数: |
4657 次 |
| 最近记录: |