The program needs to be constantly improved. It is done in the morning. When you look at it again in the afternoon, you will feel that it is not perfect.
For example: http://www.jb51.net/article/33563.htmchange "insus.net" to the following example:
In this article and the previous improvement section, you may be aware of the animation demonstration, mainly because the updates and deletions of GridVeiw will be available in each row. Therefore, Insus. NET extracts the data and places it outside the GridView. As a result, multiple records are updated at a time, and Insus. NET has recorded videos a long time ago. Another is delete. a CheckBox is placed in the first column of each row, allowing you to delete records.Copy codeThe Code is as follows: <asp: TemplateField>
<ItemStyle BorderWidth = "1" BorderColor = "# c0c0c0" Width = "1%"/>
<ItemTemplate>
<Asp: CheckBox ID = "CheckBox1" runat = "server" onclick = "Javascript: changeRowBgColor (this)"/>
</ItemTemplate>
</Asp: TemplateField>
The user is prompted to confirm before deletion, but a problem occurs here, that is, to determine whether there is a selection record, and then the confirm user confirms deletion.
There is also a point of attention, that is, after selecting the CheckBox, the line can be Highlight, the implementation side can refer to: http://www.jb51.net/article/33558.htm
The following complete code is for reference only: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: TableHeaderRow>
<Asp: TableRow Height = "20">
<Asp: TableCell BorderWidth = "1" BorderColor = "# c0c0c0">
<Asp: TextBox ID = "txt_CName" runat = "Server" CssClass = "textbox"/>
</Asp: TableCell>
<Asp: TableCell BorderWidth = "1" BorderColor = "# c0c0c0">
<Asp: TextBox ID = "txt_EName" runat = "Server" CssClass = "textbox"/>
</Asp: TableCell>
</Asp: TableRow>
</Asp: Table>
<Div style = "margin-top: 3px; margin-bottom: 3px; padding: 3px;">
<Asp: Button ID = "ButtonInsert" Text = "Insert" runat = "Server" OnClick = "ButtonInsert_Click"/>
<Asp: Button ID = "ButtonUpdate" Text = "Update" runat = "Server" OnClick = "ButtonUpdate_Click"/>
<Asp: Button ID = "ButtonDelete" Text = "Delete" runat = "Server" OnClick = "ButtonDelete_Click"
CausesValidation = "false"/>
</Div>
<Asp: GridView ID = "GvCutterType" runat = "server" DataKeyNames = "CutterTypeId" AutoGenerateColumns = "false"
CellPadding = "2" CellSpacing = "0" Width = "100%" BorderWidth = "0" BorderColor = "# c0c0c0"
RowStyle-Height = "20" ShowHeader = "false">
<Columns>
<Asp: TemplateField>
<ItemStyle BorderWidth = "1" BorderColor = "# c0c0c0" Width = "1%"/>
<ItemTemplate>
<Asp: CheckBox ID = "CheckBox1" runat = "server" onclick = "Javascript: changeRowBgColor (this)"/>
</ItemTemplate>
</Asp: TemplateField>
<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>
</Columns>
</Asp: GridView>
Xxx. aspx. cs:Copy codeThe Code is as follows: protected void ButtonInsert_Click (object sender, EventArgs e)
{
// Do Insert something
// Obj. Insert (......);
}
Protected void ButtonUpdate_Click (object sender, EventArgs e)
{
// Reference this url: http://www.cnblogs.com/insus/articles/1400150.html
}
Protected void ButtonDelete_Click (object sender, EventArgs e)
{
// String dataKeyNames = xxx;
// String [] arr = dataKeyNames. Substring (1). Split (',');
Try
{
Foreach (string s in arr)
{
// Obj. Delter (s );
}
}
Catch (Exception ex)
{
// Alert exception message
}
}