The user operation interface is simplified, and the addition function cannot be simplified. However, if the display, edit, update, and delete operations are performed in the GridView, the user is allowed to edit the settings. You need to click the button to edit the settings, or cancel editing.
To solve this problem, Insus. NET comes up with some improvement methods. You can refer to the following demo:
Add the following content at, January 7:
The preceding implementation only combines Table and GridView.
Here, Gridveiw directly uses the ItemTemplate template, omitting the EditItemTemplate template. The OnRowEditing and OnRowCancelingEdit events are also omitted.
As follows:
Then, the content of EditItemTemplate is moved to the ItemTemplate and replaced.
The complete code is as follows:
Copy codeThe Code is as follows:
<Asp: Table ID = "Table1" runat = "server" CssClass = "table" CellPadding = "2" CellSpacing = "0">
<Asp: TableHeaderRow Height = "20" BackColor = "# efebde" BorderWidth = "1" BorderColor = "# c0c0c0">
<Asp: TableHeaderCell BackColor = "# efebde" BorderWidth = "1" BorderColor = "# c0c0c0">
Chinese Name
</Asp: TableHeaderCell>
<Asp: TableHeaderCell BackColor = "# efebde" BorderWidth = "1" BorderColor = "# c0c0c0" Width = "50%">
English Name
</Asp: TableHeaderCell>
<Asp: TableHeaderCell BackColor = "# efebde" BorderWidth = "1" BorderColor = "# c0c0c0" Width = "10%">
Edit
</Asp: TableHeaderCell>
</Asp: TableHeaderRow>
<Asp: TableRow Height = "20">
<Asp: TableCell BorderWidth = "1" BorderColor = "# c0c0c0">
<Asp: TextBox ID = "txt_CName" runat = "Server"/>
</Asp: TableCell>
<Asp: TableCell BorderWidth = "1" BorderColor = "# c0c0c0">
<Asp: TextBox ID = "txt_EName" runat = "Server"/>
</Asp: TableCell>
<Asp: TableCell BorderWidth = "1" BorderColor = "# c0c0c0">
<Asp: Button ID = "ButtonInsert" Text = "Insert" runat = "Server" OnClick = "ButtonInsert_Click"/>
</Asp: TableCell>
</Asp: TableRow>
</Asp: Table>
<Div style = "margin-top: 3px; margin-bottom: 3px; padding: 3px;">
</Div>
<Asp: GridView ID = "GvCutterType" runat = "server" DataKeyNames = "CutterTypeId" AutoGenerateColumns = "false"
CellPadding = "2" CellSpacing = "0" Width = "100%" BorderWidth = "0" BorderColor = "# c0c0c0"
OnRowDeleting = "GvCutterType_OnDeleteCommand" OnRowUpdating = "GvCutterType_OnUpdateCommand"
RowStyle-Height = "20" ShowHeader = "false">
<Columns>
<Asp: TemplateField>
<ItemStyle BorderWidth = "1" BorderColor = "# c0c0c0"/>
<ItemTemplate>
<Asp: TextBox ID = "txtCName" runat = "server" Text = '<% # Eval ("CName") %>'> </asp: TextBox>
</ItemTemplate>
</Asp: TemplateField>
<Asp: TemplateField>
<ItemStyle BorderWidth = "1" BorderColor = "# c0c0c0" Width = "50%"/>
<ItemTemplate>
<Asp: TextBox ID = "txtEName" runat = "server" Text = '<% # Eval ("EName") %>'> </asp: TextBox>
</ItemTemplate>
</Asp: TemplateField>
<Asp: TemplateField HeaderText = "edit">
<ItemStyle BorderWidth = "1" BorderColor = "# c0c0c0" Width = "5%"/>
<ItemTemplate>
<Asp: Button ID = "Button1" runat = "server" CommandName = "Update" Text = "Update"/>
</ItemTemplate>
</Asp: TemplateField>
<Asp: TemplateField HeaderText = "delete">
<ItemStyle BorderWidth = "1" BorderColor = "# c0c0c0" Width = "5%"/>
<ItemTemplate>
<Asp: Button ID = "Button2" runat = "server" CommandName = "Delete" Text = "Delete"/>
</ItemTemplate>
</Asp: TemplateField>
</Columns>
</Asp: GridView>
Xxx. aspx. cs:
Copy codeThe Code is as follows:
Protected void ButtonInsert_Click (object sender, EventArgs e)
{
// Do Insert something
}
Protected void GvCutterType_OnUpdateCommand (object sender, GridViewUpdateEventArgs e)
{
// Do update something
}
Protected void GvCutterType_OnDeleteCommand (object sender, GridViewDeleteEventArgs e)
{
// Do delete something
}