手动绑定数据到GridView并实现编辑_删除_取消···
- 格式:doc
- 大小:212.50 KB
- 文档页数:7
效果图:前台代码:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default 5" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""/TR/xhtml 1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head runat="server"><title>无标题页</title></head><body><form id="form1" runat="server"><div align="center"><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"CellPadding="4" ForeColor="#333333" GridLines="None" Height="285px"onrowcancelingedit="GridView1_RowCancelingEdit"onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"onrowupdating="GridView1_RowUpdating" Width="771px"><FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /><RowStyle BackColor="#F7F6F3" ForeColor="#333333" /><Columns><asp:BoundField DataField="id" HeaderText="学号" /><asp:BoundField DataField="name" HeaderText="姓名" /><asp:BoundField DataField="sex" HeaderText="性别" /><asp:BoundField DataField="age" HeaderText="年龄" /><asp:BoundField DataField="department" HeaderText="专业" /><asp:BoundField DataField="grade" HeaderText="班级" /><asp:CommandField HeaderText="编辑 " ShowEditButton="True" /><asp:CommandField HeaderText="选择" ShowSelectButton="True" /><asp:TemplateField HeaderText="删除 " ShowHeader="False"><ItemTemplate><asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"CommandName="Delete" Text="删除" OnClientClick="return confirm('你确定要删除吗?')"></asp:LinkButton></ItemTemplate></asp:TemplateField></Columns><PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /><SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /><HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /><EditRowStyle BackColor="#999999" /><AlternatingRowStyle BackColor="White" ForeColor="#284775" /></asp:GridView></div></form></body></html>后台代码:using System;using System.Collections;using System.Configuration;using System.Data;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Data.SqlClient;public partial class Default5 : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){if (!IsPostBack){Bind();}}private void Bind(){SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Personal "].ConnectionString);SqlDataAdapter adq = new SqlDataAdapter("select * from information", conn);DataSet dataset=new DataSet();adq.Fill(dataset,"information");GridView1.DataSource=dataset;GridView1.DataKeyNames=new String[]{"id"};GridView1.DataBind();}protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e){GridView1.EditIndex = e.NewEditIndex;Bind();}protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e){SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Personal "].ConnectionString);SqlCommand comm = new SqlCommand("delete from information where id='" + GridView1.D ataKeys[e.RowIndex].Value.ToString() + "'",conn);conn.Open();try{int i = Convert.ToInt32(comm.ExecuteNonQuery());if (i > 0){Response.Write("<script language=javascript>alert('删除成功!')</script>");}else{Response.Write("<script language=javascript>alert('删除失败!')</script>");}Bind();}catch (Exception erro){Response.Write("错误信息:"+erro.Message);}finally{conn.Close();}}protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e){string id = ((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text.ToString().Trim ();string name = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.ToString().T rim();string sex = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString().Tri m();string age= ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.ToString().Tri m();string department = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.ToStri ng().Trim();string grade = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text.ToString().T rim();SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Personal "].ConnectionString);SqlCommand comm = new SqlCommand("update information set id='"+id+"', name='"+name +"' , sex='"+sex+"' , age='"+age+"' , department='"+department+"' , grade='"+grade+"' where id='"+GridView1.DataKeys[e.RowIndex].Value.ToString()+"'", conn);conn.Open();try{int i = Convert.ToInt32(comm.ExecuteNonQuery());if (i > 0){Response.Write("<script language=javascript>alert('保存成功!')</script>");}else{Response.Write("<script language=javascript>alert('保存失败!')</script>");}GridView1.EditIndex = -1;Bind();}catch (Exception erro){Response.Write("错误信息:" + erro.Message);}finally{conn.Close();}}protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e){GridView1.EditIndex = -1;Bind();}}For spatial database network environment,In this paper, related topics ,Spatial database network environment (SQL Server) conducted a study of the bining aspects of professional knowledge, with the rapid development of Internet technology, GIS technology has also been a lot of development.WebGIS also been widely used for people to start using database technology also previously stand-alone network, then and now.WebGIS and database storage combined with the use of attribute data,for map development.The main mention Rapid Storage Technology spatial database data,And the rapid transfer to a policy server and the client's.The main contents of this paper are:1 In various types of spatial database for storing attribute data of small-scale map of the target multimedia data, and some data, the data model is the core database, the key data is stored.2 Under the restrictions of network bandwidth, network transmission belt to the difficulty, on the basis of a combination of network technology, data compression applications condensation client cache technology to achieve data transmission network.3 Based on the data in ArcMap and ArcSDE bound to achieve publish dynamic maps, in order to achieve the map deleting, editing and other operations.4 cached map service to achieve the object pool strategy, thereby speeding up the response speed of the map.5 shows a map-based Chengguan District of Lanzhou City, conducteda specific design and functionality of the system, has implemented a system user login, query retrieval, delete map, the map editor and layers of management and other operations.。