datagrid分頁,排序,跨頁多選。

 datagrid分頁,排序,跨頁多選。可以分頁後還是排序的。
如果大家測出什麼bug,請留言,大家一起討論。
如果大家有什麼別的好文章請貼出聯接共享。
好的文章待續ing。

  1 None.gif using  System;
  2 None.gif using  System.Collections;
  3 None.gif using  System.ComponentModel;
  4 None.gif using  System.Data;
  5 None.gif using  System.Drawing;
  6 None.gif using  System.Web;
  7 None.gif using  System.Web.SessionState;
  8 None.gif using  System.Web.UI;
  9 None.gif using  System.Web.UI.WebControls;
 10 None.gif using  System.Web.UI.HtmlControls;
 11 None.gif using  System.Xml;
 12 None.gif using  System.Xml.XPath;
 13 None.gif using  System.Text;
 14 None.gif
 15 None.gif namespace  WebApplication4
 16 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 17ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
 18InBlock.gif    /// WebForm1 的摘要描述。
 19ExpandedSubBlockEnd.gif    /// </summary>

 20InBlock.gif    public class WebForm1 : System.Web.UI.Page
 21ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 22InBlock.gif        protected System.Web.UI.HtmlControls.HtmlInputHidden hidselectindex;
 23InBlock.gif        protected System.Web.UI.WebControls.Label Label1;
 24InBlock.gif        protected System.Web.UI.WebControls.Button Button1;
 25InBlock.gif        protected System.Web.UI.WebControls.Label SortOrder;
 26InBlock.gif        protected System.Web.UI.WebControls.Label RequestedPage;
 27InBlock.gif        protected System.Web.UI.WebControls.DataGrid DataGrid1;
 28InBlock.gif    
 29InBlock.gif        private void Page_Load(object sender, System.EventArgs e)
 30ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 31InBlock.gif            // 在這裡放置使用者程式碼以初始化網頁
 32InBlock.gif            if(!Page.IsPostBack)
 33ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 34InBlock.gif                SortOrder.Text = "Name";
 35InBlock.gif                this.RequestedPage.Text="0";
 36InBlock.gif
 37InBlock.gif                Bind();
 38ExpandedSubBlockEnd.gif            }

 39InBlock.gif            select();
 40InBlock.gif//            add();
 41ExpandedSubBlockEnd.gif        }

 42InBlock.gif
 43ContractedSubBlock.gifExpandedSubBlockStart.gif        Web Form 設計工具產生的程式碼#region Web Form 設計工具產生的程式碼
 44InBlock.gif        override protected void OnInit(EventArgs e)
 45ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 46InBlock.gif            //
 47InBlock.gif            // CODEGEN: 此為 ASP.NET Web Form 設計工具所需的呼叫。
 48InBlock.gif            //
 49InBlock.gif            InitializeComponent();
 50InBlock.gif            base.OnInit(e);
 51ExpandedSubBlockEnd.gif        }

 52InBlock.gif        
 53ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 54InBlock.gif        /// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
 55InBlock.gif        /// 這個方法的內容。
 56ExpandedSubBlockEnd.gif        /// </summary>

 57InBlock.gif        private void InitializeComponent()
 58ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{    
 59InBlock.gif            this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
 60InBlock.gif            this.DataGrid1.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.DataGrid1_SortCommand);
 61InBlock.gif            this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
 62InBlock.gif            this.Button1.Click += new System.EventHandler(this.Button1_Click);
 63InBlock.gif            this.Load += new System.EventHandler(this.Page_Load);
 64InBlock.gif
 65ExpandedSubBlockEnd.gif        }

 66ExpandedSubBlockEnd.gif        #endregion

 67InBlock.gif        private  void Bind()
 68ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 69InBlock.gif            DataSet ds=new DataSet();
 70InBlock.gif            ds.ReadXml(Server.MapPath("user.xml"));
 71InBlock.gif            DataView dv=new DataView();
 72InBlock.gif            dv=ds.Tables[0].DefaultView;
 73InBlock.gif            this.DataGrid1.DataSource=ds.Tables[0].DefaultView;
 74InBlock.gif            if(Convert.ToInt32(this.RequestedPage.Text)>=Convert.ToInt32(ds.Tables[0].Rows.Count/this.DataGrid1.PageSize))
 75InBlock.gif                 RequestedPage.Text = "0";
 76InBlock.gif            dv.Sort=SortOrder.Text;
 77InBlock.gif            this.DataGrid1.CurrentPageIndex=Convert.ToInt32(this.RequestedPage.Text);
 78InBlock.gif            this.DataGrid1.DataBind();
 79InBlock.gif            select();
 80InBlock.gif//            add();
 81ExpandedSubBlockEnd.gif        }

 82InBlock.gif
 83InBlock.gif        private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
 84ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 85InBlock.gif            this.RequestedPage.Text=e.NewPageIndex.ToString();
 86InBlock.gif            Bind();
 87ExpandedSubBlockEnd.gif        }

 88InBlock.gif
 89InBlock.gif
 90InBlock.gif        private void select()
 91ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{    
 92InBlock.gif            foreach ( DataGridItem item in this.DataGrid1.Controls[0].Controls) 
 93ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif
 94InBlock.gif                if (item.ItemType == ListItemType.Header) 
 95ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif
 96InBlock.gif                    
 97InBlock.gif                    CheckBox CheckBox1=(CheckBox)item.FindControl("CheckBox1"); 
 98InBlock.gif                    System.Text.StringBuilder strscript = new System.Text.StringBuilder("<script language='javascript'> \n"); 
 99InBlock.gif                    strscript.Append(" function checkstatus() { \n"); 
100InBlock.gif                    strscript.Append(" var ball = true; \n"); 
101InBlock.gif                    strscript.Append(" ball = document.all('" + CheckBox1.ClientID + "').checked; \n"); 
102InBlock.gif
103InBlock.gif                    for(int i=0; i<this.DataGrid1.Items.Count ; i++
104ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif
105InBlock.gif                        strscript.Append(" document.all('" + ((HtmlInputCheckBox)(this.DataGrid1.Items[i].Cells[0].FindControl("CheckBox2"))).ClientID+ "').checked = ball; \n");
106InBlock.gif                        strscript.Append(" AddRemoveValues(document.all('" + ((HtmlInputCheckBox)(this.DataGrid1.Items[i].Cells[0].FindControl("CheckBox2"))).ClientID+ "')); \n");
107ExpandedSubBlockEnd.gif                    }
 
108InBlock.gif                    strscript.Append(" } \n"); 
109InBlock.gif                    strscript.Append("</script> \n"); 
110InBlock.gif                    if(!Page.IsClientScriptBlockRegistered("checkstatus")) 
111InBlock.gif                        Page.RegisterClientScriptBlock("checkstatus",strscript.ToString()); 
112InBlock.gif                    CheckBox1.Attributes.Add("onclick","checkstatus()"); 
113InBlock.gif                    return
114ExpandedSubBlockEnd.gif                }
 
115ExpandedSubBlockEnd.gif            }

116ExpandedSubBlockEnd.gif        }

117InBlock.gif
118InBlock.gif        private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
119ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
120InBlock.gif            if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
121ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
122InBlock.gif                if(hidselectindex.Value.IndexOf(e.Item.Cells[1].Text) >= 0 )
123ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
124InBlock.gif                    HtmlInputCheckBox CheckBox2 = (HtmlInputCheckBox)(e.Item.Cells[0].FindControl("CheckBox2"));
125InBlock.gif                    CheckBox2.Checked = true;
126ExpandedSubBlockEnd.gif                }

127ExpandedSubBlockEnd.gif            }

128InBlock.gif
129ExpandedSubBlockEnd.gif        }

130InBlock.gif
131InBlock.gif        private void Button1_Click(object sender, System.EventArgs e)
132ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
133InBlock.gif            Label1.Text = hidselectindex.Value.Replace(",","<li>");
134InBlock.gif
135ExpandedSubBlockEnd.gif        }

136InBlock.gif
137InBlock.gif        private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
138ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
139InBlock.gif         if(SortOrder.Text.Trim()==e.SortExpression.Trim())
140InBlock.gif                SortOrder.Text = e.SortExpression.Trim() + " desc";
141InBlock.gif        else
142InBlock.gif            SortOrder.Text = e.SortExpression.Trim();
143InBlock.gif            Bind();
144InBlock.gif
145ExpandedSubBlockEnd.gif        }

146InBlock.gif
147InBlock.gif        
148InBlock.gif
149ExpandedSubBlockEnd.gif    }

150ExpandedBlockEnd.gif}

151 None.gif
原代碼:
/Files/gjcn/WebForm1.rar

转载于:https://www.cnblogs.com/gjcn/archive/2006/03/21/354741.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 JeeCG Datagrid 中双击行进行编辑时,可以使用 EasyUI 的 ComboGrid 组件来实现下拉框多选。 首先,在需要进行多选的列中使用 ComboGrid 组件,例如: ``` {field:'city',title:'City',width:80,editor:{ type:'combogrid', options:{ panelWidth:400, idField:'id', textField:'text', url:'get_cities.php', multiple:true, columns:[[ {field:'id',title:'ID',width:60}, {field:'text',title:'City Name',width:120}, {field:'country',title:'Country',width:100} ]] } }} ``` 在上面的代码中,我们将一个名为 `city` 的列使用了 ComboGrid 组件,并设置了 `multiple:true` 以启用多选功能。同时,我们也设置了 ComboGrid 组件的 `url` 属性来指定获取下拉框选项的数据源。 接下来,我们需要编写 `get_cities.php` 文件来获取下拉框选项的数据源。在这个文件中,我们可以使用 PHP 代码从数据库中获取城市列表,然后将其以 JSON 格式返回给前端页面。 示例代码: ```php <?php $host = 'localhost'; $user = 'root'; $pass = 'password'; $dbname = 'test'; // Connect to database $conn = mysqli_connect($host, $user, $pass, $dbname); if (!$conn) { die('Could not connect: ' . mysqli_error()); } // Retrieve city list from database $result = mysqli_query($conn, 'SELECT * FROM cities'); // Convert result to JSON format $rows = array(); while ($r = mysqli_fetch_assoc($result)) { $rows[] = $r; } echo json_encode($rows); // Close database connection mysqli_close($conn); ?> ``` 在上面的 PHP 代码中,我们首先连接到数据库,然后从 `cities` 表中获取城市列表,并将其转换为 JSON 格式返回给前端页面。最后,我们关闭数据库连接。 当用户在 JeeCG Datagrid 中双击行进行编辑时,会弹出一个下拉框供用户选择。用户可以通过在下拉框中进行搜索或直接选择多个选项来完成多选操作。用户选择的选项会以逗号分隔的字符串形式保存在 JeeCG Datagrid 中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值