Coolite Cool Study 1 在Grid中用ComboBox 来编辑数据

官方有一个关于Grid CURD 的例子: http://examples.coolite.com/Examples/GridPanel/WebService_Connections/HandlerUsing/   我在其基础上稍微修改一下, 用ComboBox作为Grid的Editor:

 

先show一下效果给大家坚持看下去的动力:

Coolite Cool Study 1 在Grid中用ComboBox 来编辑数据_第1张图片

关键代码:

复制代码 代码如下:

Width="150">

ValueField="Name" TypeAhead="false" LoadingText="Searching..." Width="570" PageSize="10"
Editable="true" Mode="Remote" MinListWidth="200" ItemSelector="tr.search-item"
MinChars="1" MsgTarget="Side" TriggerAction="All" Grow="true">







由于ComboBox作为Editor,是不能直接配置模板的,所以模板要独立写:
复制代码 代码如下:



















Name

Desc
{Name} {Desc}




再加上这个比较Cool的table样式就基本上完成了:
复制代码 代码如下:


body, table.t1
{
font-size: 12px;
}
table.t1
{
table-layout: fixed;
empty-cells: show;
border-collapse: collapse;
margin: 0 auto;
}
td
{
height: 20px;
}
h1, h2, h3
{
font-size: 12px;
margin: 0;
padding: 0;
}
table.t1
{
border: 1px solid #cad9ea;
color: #666;
}
table.t1 th
{
background-image: url(/extjs/resources/images/default/panel/white-top-bottom-gif/coolite.axd);
background-repeat: repeat-x;
height: 22px;
}
table.t1 td, table.t1 th
{
border: 1px solid #cad9ea;
padding: 0 1em 0;
}
table.t1 tr.a1
{
background-color: #f5fafe;
}

Enjoy yourself!
完整的代码:
Html
复制代码 代码如下:

<%@ Page Language="C#" AutoEventWireup="true"%>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>









































Name

Desc
{Name} {Desc}



































TrackMouseOver="true" ClicksToEdit="1" AutoExpandColumn="CompanyName" Height="500">

















Width="150">

ValueField="Name" TypeAhead="false" LoadingText="Searching..." Width="570" PageSize="10"
Editable="true" Mode="Remote" MinListWidth="200" ItemSelector="tr.search-item"
MinChars="1" MsgTarget="Side" TriggerAction="All" Grow="true">


































































CustomerHandler.ashx
复制代码 代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Coolite.Ext.Web;
namespace WebSPN.Controllers
{
///
/// Summary description for $codebehindclassname$
///

//[WebService(Namespace = "http://tempuri.org/")]
//[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class CustomerHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string json = "";
var Request =context.Request;
string action= Request["action"];
if (action == "query")
{
Random rand=new Random();
int limit =int .Parse ( Request["limit"]);
int start =int .Parse ( Request["start"]);
IList list = new List();
for (int i = start; i < start + limit; i++)
list.Add(new Customer
{
CustomerID = "Customer" +i,
Address = "Address" +i,
City = "City" + rand.Next(1000),
CompanyName = "Com" + rand.Next(1000),
ContactName = "Contract" + rand.Next(1000),
ContactTitle = "Title" + rand.Next(1000),
Country = "Country" + rand.Next(1000),
Email = rand.Next(1000) + "@live.com",
Fax = rand.Next(1000).ToString() + rand.Next(1000),
Mobile = rand.Next(1000).ToString() + rand.Next(1000),
Notes = "Notes" + rand.Next(1000),
Phone = "Phone" + rand.Next(1000),
Region = "Region" + rand.Next(1000),
TranDate =DateTime .Now .AddDays(rand.Next(30))
});
json= Coolite.Ext.Web.JSON.Serialize(list);
json = "{data:" + json + ", totalCount:" + 100 + "}";
context.Response.Write(json);
}
else if (action == "save")
{
//saving
StoreDataHandler dataHandler = new StoreDataHandler( Request["data"]);
ChangeRecords data = dataHandler.ObjectData();
foreach (Customer customer in data.Deleted)
{
//db.Customers.Attach(customer);
//db.Customers.DeleteOnSubmit(customer);
}
foreach (Customer customer in data.Updated)
{
//db.Customers.Attach(customer);
//db.Refresh(RefreshMode.KeepCurrentValues, customer);
}
foreach (Customer customer in data.Created)
{
//db.Customers.InsertOnSubmit(customer);
}
//db.SubmitChanges();
Response sr = new Response(true);
sr.Success = true;
sr.Write();
}
else if (action == "contact")
{
string query = Request["query"]??"";
json = "[{Name:'Bruce Lee query:"+query +"',Desc:'skjfkasjdkf'},{Name:'zzz',Desc:'sffffkf'},{Name:'ssse',Desc:'zzzzzzasjdkf'},"+
"{Name:'Bruce Lee" + DateTime.Now + "',Desc:'skzzjdkf'},{Name:'zzz',Desc:'sffffkf'},{Name:'ssse',Desc:'zzzzzzasjdkf'}," +
"{Name:'Bruce Lee',Desc:'" + DateTime.Now + "'},{Name:'zzz',Desc:'sffffkf'},{Name:'ssse',Desc:'zzzzzzasjdkf'}" +
"]";
json = "{data:" + json + ", totalCount:" + 20 + "}";
context.Response.Write(json);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
public partial class Customer
{
public string CustomerID { get; set; }
public string CompanyName { get; set; }
public string ContactName { get; set; }
public string ContactTitle { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
public string Mobile { get; set; }
public string Email { get; set; }

public string WebPage { get; set; }
public string Notes { get; set; }
public DateTime TranDate { get; set; }
}
}

你可能感兴趣的:(Coolite Cool Study 1 在Grid中用ComboBox 来编辑数据)