Quickly add new rows to the DataGrid (C #)

Source: Internet
Author: User
Tags eval insert visual studio
The DataGrid code is very easy to understand, but to declare, this is to refer to the VB version of Confucius Rewrite, just because some friends say C # is not good to write.
I only write a reference for everyone. Here, thank you to Confucius.

Appe_admin.aspx

<%@ Page language= "C #" codebehind= "Appe_admin.aspx.cs" autoeventwireup= "false" inherits= "bzh_home.appe_admin"% >
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<title>appe_admin</title>
<meta name= "generator" content= "Microsoft Visual Studio. NET 7.1" >
<meta name= "Code_language" content= "C #" >
<meta name= "vs_defaultClientScript" content= "JavaScript" >
<meta name= "vs_targetschema" content= "http://schemas.microsoft.com/intellisense/ie5" >
</HEAD>
<body ms_positioning= "GridLayout" >
<form id= "Form1" method= "POST" runat= "Server" >
<font face= "Song Body" ></FONT>
<asp:datagrid id= "DATAGRID1" runat= "Server" autogeneratecolumns= "False" showfooter= "True" onitemcommand= " Itemsgrid_command "
Cellpadding= "4" backcolor= "White" borderwidth= "1px" borderstyle= "None" bordercolor= "#CC9966" >
<selecteditemstyle font-bold= "True" forecolor= "#663399" backcolor= "#FFCC66" ></SelectedItemStyle>
<itemstyle forecolor= "#330099" backcolor= "white" ></ItemStyle>
<footerstyle forecolor= "#330099" backcolor= "#FFFFCC" ></FooterStyle>
<Columns>
<asp:templatecolumn headertext= "Employee ID" >
<ItemTemplate>
<asp:label id=label3 runat= "server" text= ' <%# DataBinder.Eval (Container, "DataItem. Number")%> ' >
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:linkbutton id= "LinkButton1" runat= "Server" Commandname= "Insert" >Insert</asp:LinkButton>
</FooterTemplate>
<EditItemTemplate>
<asp:textbox id=textbox5 runat= "server" text= ' <%# DataBinder.Eval (Container, "DataItem. Number")%> ' >
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:templatecolumn headertext= "Last Name" >
<ItemTemplate>
<asp:label id=label1 runat= "server" text= ' <%# DataBinder.Eval (Container, "DataItem. User name")%> ' >
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:textbox id= "TextBox2" runat= "Server" ></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:textbox id= "TextBox1" runat= "Server" ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:templatecolumn headertext= "A-Name" >
<ItemTemplate>
<asp:label id=label2 runat= "server" text= ' <%# DataBinder.Eval (Container, "DataItem. Password")%> ' >
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:textbox id= "TextBox4" runat= "Server" ></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:textbox id= "TextBox3" runat= "Server" ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
<pagerstyle horizontalalign= "Center" forecolor= "#330099" backcolor= "#FFFFCC" ></PagerStyle>
</asp:datagrid>
</form>
</body>
</HTML>


Appe_admin.aspx.cs


Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Data.SqlClient;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;

Namespace Bzh_home
{
<summary>
Appe_admin's



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.