MagicAjax的使用

早听说magicajax是如何如何的简单,这几天总算见识到了,和以前写程序没多大区别,只要将控件包含在ajaxpanel里就OK了
源码下载: Files\huazi4995\magicajax-0.2.2-source.rar
在公司写了一个关于这个框架的应用页面,也将其源吗码编译成了支持中文的,好爽 .如下图
2007-08-14_135045.jpg

ExpandedBlockStart.gif ContractedBlock.gif <% dot.gif @ Register TagPrefix="ajax" Namespace="MagicAjax.UI.Controls" Assembly="MagicAjax"  %>
ExpandedBlockStart.gifContractedBlock.gif
<% dot.gif @ Page language="c#" Codebehind="ZiDian.aspx.cs" AutoEventWireup="false" Inherits="LSA.ActiveForm.ZiDian" ResponseEncoding="utf-8"  %>
None.gif
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"  >
None.gif
< HTML >
None.gif    
< HEAD >
None.gif        
< title > 代码类别选择 </ title >
None.gif        
< meta  content ="Microsoft Visual Studio .NET 7.1"  name ="GENERATOR" >
None.gif        
< meta  content ="C#"  name ="CODE_LANGUAGE" >
None.gif        
< meta  content ="JavaScript"  name ="vs_defaultClientScript" >
None.gif        
< meta  content ="http://schemas.microsoft.com/intellisense/ie5"  name ="vs_targetSchema" >
None.gif        
< LINK  href ="../Style/WinXP/style.css"  type ="text/css"  rel ="stylesheet" >
None.gif        
< base  target ="_self" >
ExpandedBlockStart.gifContractedBlock.gif        
< style  type ="text/css" > dot.gif .btn_2k3 {dot.gif}{ BORDER-RIGHT: #002d96 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #002d96 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 12px; FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#9DBCEA); BORDER-LEFT: #002d96 1px solid; CURSOR: hand; COLOR: black; PADDING-TOP: 2px; BORDER-BOTTOM: #002d96 1px solid }
ExpandedSubBlockStart.gifContractedSubBlock.gif    .btn 
{dot.gif}{ BORDER-RIGHT: #7b9ebd 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7b9ebd 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 12px; FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde); BORDER-LEFT: #7b9ebd 1px solid; CURSOR: hand; COLOR: black; PADDING-TOP: 2px; BORDER-BOTTOM: #7b9ebd 1px solid }
ExpandedBlockEnd.gif        
</ style >
ExpandedBlockStart.gifContractedBlock.gif        
< script  language ="javascript" > dot.gif
InBlock.gif        
function getvalue()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif        
var a=document.getElementById("txtDm").value;
InBlock.gif            alert(a);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
function returnData(dm,mc)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif    
InBlock.gif            
var strReturn="";
InBlock.gif            strReturn
=strReturn + dm + "," + mc;
InBlock.gif
InBlock.gif            window.returnValue 
= strReturn;
InBlock.gif            window.close();
InBlock.gif            
//var objList=document.getElementById("lst");
InBlock.gif
            //objList.options[0].value = strValue;
InBlock.gif
            //objList.options[0].text = strText;
InBlock.gif
            
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
function btncanel()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            window.close();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
//删除 
InBlock.gif
            function deleteOption()
ExpandedSubBlockStart.gifContractedSubBlock.gif           
dot.gif{
InBlock.gif           
InBlock.gif                
var addOption=document.createElement("option");
InBlock.gif               
var index1;
InBlock.gif            
//alert(addOption);
InBlock.gif
               if(document.Form1.lst.length==0)
InBlock.gif               
return(false);
InBlock.gif               index1
=document.Form1.lst.selectedIndex; 
InBlock.gif               
if(index1<0)
ExpandedSubBlockStart.gifContractedSubBlock.gif               
dot.gif{
InBlock.gif                    alert(
"请先选择!!!");
InBlock.gif                    
return(false);
ExpandedSubBlockEnd.gif               }

InBlock.gif               addOption.text
=document.Form1.lst.options(index1).text;
InBlock.gif               addOption.value
=document.Form1.lst.value; 
InBlock.gif            
InBlock.gif               
//document.Form1.lst_TeZheng.add(addOption);
InBlock.gif
              
InBlock.gif              
InBlock.gif               document.Form1.lst.remove (index1);
InBlock.gif               
ExpandedSubBlockEnd.gif           }

InBlock.gif           
InBlock.gif         
function SetValue()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif        
InBlock.gif
InBlock.gif            
//var objList = document.getElementById("lst");
InBlock.gif
            //if(!(objList.length <%=num%>))
InBlock.gif
            //{
InBlock.gif
            //    alert("输入的待选项验证失败,应 <%=num%> 。");
InBlock.gif
            //    return;
InBlock.gif
            //}
InBlock.gif
        
InBlock.gif        
InBlock.gif        
InBlock.gif            
var strReturn="";
InBlock.gif            
InBlock.gif            
var objList = document.getElementById("lst");
InBlock.gif            
InBlock.gif            
for(var i=0;i<objList.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                    
//返回给文本框
InBlock.gif
                    //strReturn = strReturn + "," + objList.options[i].text;
InBlock.gif
                    //返回给多选框
InBlock.gif
                    strReturn = strReturn + "|" + objList.options[i].value + "," + objList.options[i].text;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(strReturn !="")
InBlock.gif                strReturn 
= strReturn.substring(1,strReturn.length);
InBlock.gif
InBlock.gif
InBlock.gif            
InBlock.gif            window.returnValue 
= strReturn;
InBlock.gif            window.close();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
function KeyDown()dot.gif{    
InBlock.gif     
InBlock.gif  
InBlock.gif     
//alert(event.keyCode);
InBlock.gif
     
ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (event.keyCode==191)dot.gif
InBlock.gif        
//alert('123123');
InBlock.gif
        event.keyCode=0; event.returnValue=false;
ExpandedSubBlockEnd.gif         }
 
InBlock.gif         
InBlock.gif         
ExpandedSubBlockEnd.gif  }

ExpandedBlockEnd.gif        
</ script >
None.gif    
</ HEAD >
None.gif    
< body  MS_POSITIONING ="FlowLayout" >
None.gif        
< form  id ="Form1"  method ="post"  runat ="server" >
None.gif            
< FONT  face ="宋体" ></ FONT >
None.gif            
< br >
None.gif            
< br >
None.gif            
< center >
None.gif                
< ajax:ajaxpanel  id ="AjaxPanel1"  runat ="server" >
None.gif                    
< TABLE  id ="Table1"  cellSpacing ="4"  cellPadding ="4"  width ="340"  border ="1" >
None.gif                        
< TR >
None.gif                            
< TD >< FONT  face ="宋体" > 关键字: </ FONT >
None.gif                                
< asp:TextBox  id ="txtDm"  runat ="server"  ToolTip ="输入代码或拼音首字母索引"  Width ="70px" ></ asp:TextBox >
None.gif                                
< asp:LinkButton  id ="lbShowResult"  runat ="server" > 搜  索 </ asp:LinkButton ></ TD >
None.gif                            
< TD >
None.gif                                
< asp:Button  id ="btnPre"  runat ="server"  CssClass ="btn"  Text ="前一页" ></ asp:Button >
None.gif                                
< asp:Button  id ="btnNext"  runat ="server"  CssClass ="btn"  Text ="下一页" ></ asp:Button ></ TD >
None.gif                        
</ TR >
None.gif                        
< TR >
None.gif                            
< TD  colSpan ="2" >
None.gif                                
< asp:DataGrid  id ="dg"  runat ="server"  ToolTip ="双击可以选择"  Width ="100%"  AllowPaging ="True"  AutoGenerateColumns ="False"
None.gif                                    ShowHeader
="False"  DataKeyField ="dm" >
None.gif                                    
< Columns >
None.gif                                        
< asp:TemplateColumn >
None.gif                                            
< HeaderStyle  Width ="10px" ></ HeaderStyle >
None.gif                                            
< HeaderTemplate >
None.gif                                                
< INPUT  id ="checkAll"  type ="checkbox"  CommandName ="Select2" >
None.gif                                            
</ HeaderTemplate >
None.gif                                            
< ItemTemplate >
None.gif                                                
< asp:CheckBox  id ="chk"  runat ="server"  AutoPostBack ="True" ></ asp:CheckBox >
None.gif                                            
</ ItemTemplate >
None.gif                                        
</ asp:TemplateColumn >
None.gif                                        
< asp:TemplateColumn >
None.gif                                            
< HeaderStyle  Width ="10px" ></ HeaderStyle >
None.gif                                            
< ItemTemplate >
None.gif                                                
< asp:RadioButton  id ="rad"  runat ="server"  AutoPostBack ="True" ></ asp:RadioButton >
None.gif                                            
</ ItemTemplate >
None.gif                                        
</ asp:TemplateColumn >
None.gif                                        
< asp:ButtonColumn  Visible ="False"  Text ="选择"  CommandName ="Select" >
None.gif                                            
< HeaderStyle  Width ="10px" ></ HeaderStyle >
None.gif                                        
</ asp:ButtonColumn >
None.gif                                        
< asp:BoundColumn  DataField ="dm" >
None.gif                                            
< HeaderStyle  Width ="20px" ></ HeaderStyle >
None.gif                                        
</ asp:BoundColumn >
None.gif                                        
< asp:BoundColumn  DataField ="name" >
None.gif                                            
< HeaderStyle  Width ="200px" ></ HeaderStyle >
None.gif                                        
</ asp:BoundColumn >
None.gif                                    
</ Columns >
None.gif                                    
< PagerStyle  Visible ="False"  Mode ="NumericPages" ></ PagerStyle >
None.gif                                
</ asp:DataGrid ></ TD >
None.gif                        
</ TR >
None.gif                        
< TR >
None.gif                            
< TD  id ="tddrp"  style ="HEIGHT: 67px"  align ="center"  colSpan ="2"  runat ="server" >
None.gif                                
< asp:ListBox  id ="lst"  runat ="server" ></ asp:ListBox >< INPUT  id ="btndelete"  style ="DISPLAY: none"  onclick ="javascript:deleteOption();"  type ="button"
None.gif                                    value
="删 除" > &nbsp;
None.gif                                
< asp:Button  id ="btndel"  runat ="server"  CssClass ="btn"  Text ="删 除" ></ asp:Button ></ TD >
None.gif                        
</ TR >
None.gif                        
< TR >
None.gif                            
< TD  id ="tdbtn"  align ="center"  colSpan ="2"  runat ="server" >< INPUT  class ="btn"  onclick ="SetValue();"  type ="button"  value ="确 定" > &nbsp;&nbsp;&nbsp;
None.gif                                
< INPUT  class ="btn"  id ="btncanel"  onclick ="javascript:window.close();"  type ="button"  value ="取  消" >
None.gif                            
</ TD >
None.gif                        
</ TR >
None.gif                    
</ TABLE >
None.gif                
</ ajax:ajaxpanel >
None.gif            
</ center >
None.gif        
</ form >
None.gif    
</ body >
None.gif
</ HTML >
None.gif
 
None.gif using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Web;
None.gif
using  System.Web.SessionState;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.Data.OracleClient;
None.gif
None.gif
namespace  LSA.ActiveForm
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// ZiDian 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class ZiDian : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected System.Web.UI.WebControls.DataGrid dg;
InBlock.gif        
protected MagicAjax.UI.Controls.AjaxPanel AjaxPanel1;
InBlock.gif        
protected System.Web.UI.WebControls.LinkButton lbShowResult;
InBlock.gif        
protected System.Web.UI.WebControls.ListBox lst;
InBlock.gif        
protected string strTableName="";
InBlock.gif        
protected System.Web.UI.WebControls.Button btndel;
InBlock.gif        
protected System.Web.UI.WebControls.Button btnNext;
InBlock.gif        
protected System.Web.UI.WebControls.Button btnPre;
InBlock.gif        
protected string num = "1";
InBlock.gif        
protected System.Web.UI.HtmlControls.HtmlTableCell tddrp;
InBlock.gif        
protected System.Web.UI.WebControls.TextBox txtDm;
InBlock.gif        
protected System.Web.UI.HtmlControls.HtmlTableCell tdbtn;
InBlock.gif        
protected System.Web.UI.HtmlControls.HtmlInputText txtDm2;
InBlock.gif    
ContractedSubBlock.gifExpandedSubBlockStart.gif        
加载#region 加载
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//txtDm.Attributes.Add("onkeydown","if (event.keyCode==43){ alert(你输入的不是数字); } ");
InBlock.gif
InBlock.gif
InBlock.gif            
//Ajax.Utility.RegisterTypeForAjax(typeof(ZiDian));
InBlock.gif

InBlock.gif            
string strScript = Page.GetPostBackClientEvent(lbShowResult, "");
InBlock.gif            txtDm.Attributes.Add(
"onkeyup", strScript);
InBlock.gif            
// 在此处放置用户代码以初始化页面
InBlock.gif
             strTableName=Request.QueryString["TableName"].ToString();
InBlock.gif
InBlock.gif            
if(Request.QueryString["NUM"]!=null)
InBlock.gif                
this.num=Request.QueryString["NUM"].ToString();
InBlock.gif
InBlock.gif
InBlock.gif            
InBlock.gif
InBlock.gif            
//判断是否显示秒下拉列表与确定按钮
InBlock.gif
//            if(Request.QueryString["drp"]!=null)
InBlock.gif
//            {
InBlock.gif
//                tddrp.Attributes.Add("style","display:none");
InBlock.gif
//                tdbtn.Attributes.Add("style","display:none");
InBlock.gif
//            }
InBlock.gif

InBlock.gif            
if(!Page.IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                GetData(strTableName);
InBlock.gif
InBlock.gif                IsShow();
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.lbShowResult.Click += new System.EventHandler(this.lbShowResult_Click);
InBlock.gif            
this.btnPre.Click += new System.EventHandler(this.btnPre_Click);
InBlock.gif            
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
InBlock.gif            
this.dg.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dg_ItemCreated);
InBlock.gif            
this.dg.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dg_ItemCommand);
InBlock.gif            
this.dg.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dg_ItemDataBound);
InBlock.gif            
this.btndel.Click += new System.EventHandler(this.btndel_Click);
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
绑定数据#region 绑定数据
InBlock.gif        
InBlock.gif        
private void GetData(string TableName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif        
InBlock.gif            
string strSql="";
InBlock.gif            
if(TableName.ToUpper()=="CODE_SHENSHIXIAN")    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                strSql
=string.Format("select dm ,name from {0} where dm  like '%{1}%' or UPPER(pym) like '%{1}%' or  name  like '%{1}%'  order by px,dm asc ",TableName,txtDm.Text.Trim().ToUpper());
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else if(TableName.ToUpper()=="BUMEN")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                strSql
=string.Format("select BIANHAO AS dm ,MINGCHENG AS name from {0} where BIANHAO  like '%{1}%' or UPPER(BEIZHU) like '%{1}%' or  MINGCHENG  like '%{1}%'  order by BIANHAO asc ",TableName,txtDm.Text.Trim().ToUpper());
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif                strSql
=string.Format("select dm ,name from {0} where dm  like '%{1}%' or UPPER(pym) like '%{1}%' or name like '%{1}%' order by dm asc ",TableName,txtDm.Text.Trim().ToUpper());
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            DataSet ds
=LSA.DataProvider.DatabaseHelper.Instance().ExecuteDataSet(strSql);
InBlock.gif            dg.DataSource
=ds.Tables[0].DefaultView;
InBlock.gif            dg.DataBind();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
搜索#region 搜索
InBlock.gif        
private void lbShowResult_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            dg.CurrentPageIndex
=0;
InBlock.gif            GetData(strTableName);
InBlock.gif
InBlock.gif            IsShow();
InBlock.gif        
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
给datagrid行增加双击事件#region 给datagrid行增加双击事件
InBlock.gif        
private void dg_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
InBlock.gif            
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif    
InBlock.gif                e.Item.Attributes.Add (
"ondblclick""javascript:returnData('" + e.Item.Cells[3].Text.Replace("\n","\\n"+ "','" + e.Item.Cells[4].Text.Replace("\n","\\n"+ "');");
InBlock.gif                
InBlock.gif                
string strdm=e.Item.Cells[2].Text;
InBlock.gif                
string strmc=e.Item.Cells[3].Text;
InBlock.gif                
InBlock.gif                e.Item.Attributes.Add
InBlock.gif                    (
"onmouseover","this.className='tdbg-dark'");
InBlock.gif            
InBlock.gif                e.Item.Attributes.Add
InBlock.gif                    (
"onmouseout","this.className='tdbg'");
ExpandedSubBlockEnd.gif            }
    
InBlock.gif            
InBlock.gif            
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
dot.gif#region
InBlock.gif        
private void dg_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(e.CommandName.Equals("Select"))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string strkey=dg.DataKeys[e.Item.ItemIndex].ToString();
InBlock.gif                
string strmc=e.Item.Cells[4].Text;
InBlock.gif
InBlock.gif                ListItem item
=new ListItem(strmc,strkey);
InBlock.gif
InBlock.gif                        lst.Items.Add(item);
InBlock.gif
InBlock.gif                     
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(e.CommandName.Equals("Select2"))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
多选钮事件#region 多选钮事件
InBlock.gif        
private void cbo_CheckedChanged(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            
InBlock.gif            
for(int i=0;i<dg.Items.Count;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif            
InBlock.gif                
if(((CheckBox)dg.Items[i].FindControl("chk")).Checked==true)    
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
string strkey=dg.DataKeys[dg.Items[i].ItemIndex].ToString();
InBlock.gif                    
string strmc=dg.Items[i].Cells[4].Text;
InBlock.gif
InBlock.gif                    
//判断列表框中是否存在此值,若存在则不增加此项
InBlock.gif
                    string strLstDM=",;:";
InBlock.gif                    
for(int j=0;j<lst.Items.Count;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        strLstDM
+=lst.Items[j].Value;
InBlock.gif
ExpandedSubBlockEnd.gif                    }

InBlock.gif
InBlock.gif                    
if(strLstDM.IndexOf(strkey,0)>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif
InBlock.gif                        ListItem item
=new ListItem(strmc,strkey);
InBlock.gif                        lst.Items.Add(item);
ExpandedSubBlockEnd.gif                    }

InBlock.gif
InBlock.gif
//                    dg.Items[i].BackColor=Color.LawnGreen;
InBlock.gif
//                    dg.Items[i].Attributes.Add("style","className='tdbg-dark'");
InBlock.gif
                    
InBlock.gif                    
InBlock.gif    
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
string strkey=dg.DataKeys[dg.Items[i].ItemIndex].ToString();
InBlock.gif                    
string strmc=dg.Items[i].Cells[4].Text;
InBlock.gif                    ListItem item
=new ListItem(strmc,strkey);
InBlock.gif                    lst.Items.Remove(item);
InBlock.gif                    
InBlock.gif
//                    dg.Items[i].BackColor=Color.Yellow;
InBlock.gif
//                    dg.Items[i].Attributes.Add("BackColor","className='tdbg'");
InBlock.gif
        
InBlock.gif
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
//((CheckBox)dg.Items[i].FindControl("chk")).Checked=false;
InBlock.gif

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
单选钮事件#region 单选钮事件
InBlock.gif        
private void rdb_CheckedChanged(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string strkey="";
InBlock.gif            
string strmc="";
InBlock.gif            
for(int i=0;i<dg.Items.Count;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif
InBlock.gif            
InBlock.gif                
if(((RadioButton)dg.Items[i].FindControl("rad")).Checked==true)    
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                     strkey
=dg.DataKeys[dg.Items[i].ItemIndex].ToString();
InBlock.gif                     strmc
=dg.Items[i].Cells[4].Text;
InBlock.gif
InBlock.gif                    lst.Items.Clear();
InBlock.gif                    ListItem item
=new ListItem(strmc,strkey);
InBlock.gif                    lst.Items.Add(item);
InBlock.gif
InBlock.gif                    
InBlock.gif                    ((RadioButton)dg.Items[i].FindControl(
"rad")).Checked=false;
InBlock.gif                    
//((RadioButton)dg.Items[i].FindControl("rad")).Checked=true;
InBlock.gif

InBlock.gif                    
break;
InBlock.gif    
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif        
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
在datagrid创建item时注册事件#region 在datagrid创建item时注册事件
InBlock.gif        
private void dg_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//注册事件
InBlock.gif
                CheckBox cbo=(CheckBox)e.Item.FindControl("chk"); 
InBlock.gif                cbo.CheckedChanged
+=new EventHandler(cbo_CheckedChanged);
InBlock.gif
InBlock.gif                RadioButton rdb
=(RadioButton)e.Item.FindControl("rad");
InBlock.gif                rdb.CheckedChanged
+=new EventHandler(rdb_CheckedChanged);
InBlock.gif
InBlock.gif                
ExpandedSubBlockEnd.gif            }

InBlock.gif        
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
删除#region 删除
InBlock.gif        
private void btndel_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
for(int i=0;i<lst.Items.Count;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(lst.Items[i].Selected)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    lst.Items.RemoveAt(i);
InBlock.gif                
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
下一页#region 下一页
InBlock.gif        
private void btnNext_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int currNum=1;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
InBlock.gif
InBlock.gif
InBlock.gif                
int currIndex=dg.CurrentPageIndex;
InBlock.gif                currNum
=dg.PageCount;
InBlock.gif
InBlock.gif                
if(currNum!=currIndex+1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    dg.CurrentPageIndex
+=1;
InBlock.gif
InBlock.gif                    btnNext.Visible
=true;
InBlock.gif                    btnPre.Visible
=true;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    btnNext.Visible
=false;
InBlock.gif                    btnPre.Visible
=true;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
InBlock.gif                
InBlock.gif                GetData(strTableName);
InBlock.gif
InBlock.gif                IsShow();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                dg.CurrentPageIndex
=currNum-1;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
前一页#region 前一页
InBlock.gif        
private void btnPre_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int currNum=1;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif                
int currIndex=dg.CurrentPageIndex;
InBlock.gif
InBlock.gif                
if(currNum!=currIndex+1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    dg.CurrentPageIndex
-=1;
InBlock.gif
InBlock.gif                    btnNext.Visible
=true;
InBlock.gif                    btnPre.Visible
=true;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    btnPre.Visible
=false;
InBlock.gif                    btnNext.Visible
=true;
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
InBlock.gif
InBlock.gif                GetData(strTableName);
InBlock.gif
InBlock.gif                IsShow();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                dg.CurrentPageIndex
+=1;
ExpandedSubBlockEnd.gif            }

InBlock.gif        
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
ContractedSubBlock.gifExpandedSubBlockStart.gif        
判断单选框与多选框是否显示#region 判断单选框与多选框是否显示
InBlock.gif        
private void IsShow()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//1表示单选,其它表示多选
InBlock.gif
            if(num=="1")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
for(int i=0;i<dg.Items.Count;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    dg.Items[i].Cells[
0].Visible=false;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
for(int i=0;i<dg.Items.Count;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    dg.Items[i].Cells[
1].Visible=false;
ExpandedSubBlockEnd.gif                }

InBlock.gif
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif        
InBlock.gif        
InBlock.gif
InBlock.gif        
InBlock.gif
InBlock.gif        
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

在web.config下配置如下:
None.gif < httpModules >
None.gif                
< add  name ="MagicAjax"  type ="MagicAjax.MagicAjaxModule, MagicAjax"   />
None.gif    
</ httpModules >

转载于:https://www.cnblogs.com/huazi4995/archive/2007/08/14/855251.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值