ASP. NET simplified editing interface solution and implementation code

Source: Internet
Author: User

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
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.