利用ASP.NET AJAX实现表格更新程序
今天看了一个网站http://aspadvice.com/blogs/azamsharp/archive/2007/06/28/Edit-GridView-Using-CheckBoxes.aspx,自己做了一个小程序,表格更新程序,主要功能为使用CheckBoxe允许编辑GridView行,并且能够保存修改的信息
具体程序如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MultipleUpdateDemo.aspx.cs" Inherits="MultipleUpdateDemo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script type="text/C#" runat="server">
        [System.Web.Services.WebMethod]
        public static bool UpdateText(string categoryName, string description, string Id)
        {
            string conectionString = "Data Source=(local);Initial Catalog=Northwind;User ID=sa;Password=sa";
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(conectionString);
            conn.Open();
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("UPDATE Categories SET CategoryName = '" + categoryName + "', Description = '" + description + "' WHERE CategoryID = " + Id, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            return true;
            
        }
    </script>
    <script type="text/javascript">

    function disableGridViewTextBoxes() 
    {
        var gvControl = document.getElementById("gvCategories"); 
        var inputElements = gvControl.getElementsByTagName("INPUT"); 
        for( i = 0;i < inputElements.length; i++) 
        {
            if(isTextBox(inputElements[i])) 
            {
                inputElements[i].disabled =<span style="COLOR: #000000; BACKGROUND-COLOR: %2 
具体程序如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MultipleUpdateDemo.aspx.cs" Inherits="MultipleUpdateDemo" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script type="text/C#" runat="server">
        [System.Web.Services.WebMethod]
        public static bool UpdateText(string categoryName, string description, string Id)
        {
            string conectionString = "Data Source=(local);Initial Catalog=Northwind;User ID=sa;Password=sa";
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(conectionString);
            conn.Open();
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("UPDATE Categories SET CategoryName = '" + categoryName + "', Description = '" + description + "' WHERE CategoryID = " + Id, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            return true;
            
        }
    </script>
    <script type="text/javascript">
    function disableGridViewTextBoxes() 
    {
        var gvControl = document.getElementById("gvCategories"); 
        var inputElements = gvControl.getElementsByTagName("INPUT"); 
        for( i = 0;i < inputElements.length; i++) 
        {
            if(isTextBox(inputElements[i])) 
            {
                inputElements[i].disabled =<span style="COLOR: #000000; BACKGROUND-COLOR: %2 
                    
                


        
                
            
        
浙公网安备 33010602011771号