datagrid|数据
可能大家在使用DataGrid编辑数据的时候会觉得要点击最后的编辑列的按钮来修改数据不是很方便,在今天的例子中给出一种比较方便的操作方法:要修改数据点击这一行-》鼠标放在哪个文本框就会选中哪个文本框的内容,直接可以进行修改-》修改完毕以后双击这一行(也可以直接双击文本框)进行保存。这次使用sqlserver数据库中的northwind数据库中的Employees表作为例子。
前台:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm87</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="css.css" type="text/css" rel="stylesheet">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False" CellSpacing="1" BorderWidth="0px"
CellPadding="5" CssClass="border" DataKeyField="EmployeeID">
<ItemStyle CssClass="item"></ItemStyle>
<HeaderStyle CssClass="header"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="FirstName" HeaderText="FirstName"></asp:BoundColumn>
<asp:BoundColumn DataField="LastName" HeaderText="LastName"></asp:BoundColumn>
<asp:BoundColumn DataField="Title" HeaderText="Title"></asp:BoundColumn>
<asp:BoundColumn DataField="BirthDate" HeaderText="BirthDate" DataFormatString="{0:yyyy-MM-dd}"></asp:BoundColumn>
<asp:ButtonColumn ButtonType="LinkButton" CommandName="edit" Text="edit" Visible="False"></asp:ButtonColumn>
<asp:ButtonColumn ButtonType="LinkButton" CommandName="update" Text="update" Visible="False"></asp:ButtonColumn>
</Columns>
</asp:datagrid>
</form>
</body>
</HTML>
后台:
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 csdn
{
public class WebForm87 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;