功能齐全的DataGrid

// 目前功能:排序、单选项、复选项、合并单元格、产生序列号、联动下拉框、编辑、删除、超连接、鼠标移动改变颜色、奇偶项颜色区分等
1.html代码
< HTML >
    
< HEAD >
        
< title > DatagridTest </ title >
        
< meta  content ="Microsoft Visual Studio .NET 7.1"  name ="GENERATOR" >
        
< meta  content ="C#"  name ="CODE_LANGUAGE" >
        
< meta  content ="JavaScript"  name ="vs_defaultClientScript" >
        
< meta  content ="http://schemas.microsoft.com/intellisense/ie5"  name ="vs_targetSchema" >
        
< script  language ="javascript" >
            
function fun_option(obj)
            
{
                document.Form1.hiduserid.value
=obj.value;
            }
            
            
function chkAll_true()
            
{
                
var chkall= document.all["chkAll"];
                
var chkother= document.all["chkExport"];
                
if(chkother.length>0)
                
{
                    
for (var i=0;i<chkother.length;i++)
                    
{
                        
if(chkall.checked==true)
                        
{
                            chkother[i].checked
=true;
                        }

                        
else
                        
{
                            chkother[i].checked
=false;
                        }

                    }

                }

            }

            
            
function Delete()
            
{
                
//debugger;
                var chkother= document.all["chkExport"];
                
var temp="";
                
if(chkother.length>0)
                
{
                    
for (var i=0;i<chkother.length;i++)
                    
{
                        
if(chkother[i].checked=true)
                        
{
                            temp
+=","+chkother[i].value;
                        }
                        
                    }

                    temp
=temp.substring(1,temp.length);
                }

                
if (temp == "")
                
{
                    alert('You need to select a row 
in the list before selecting Delete./r/nPlease select a row and try again.');
                }

                
else if (window.confirm("Are you sure to delete all these?"))
                
{
                    document.Form1.hiduserid.value
=temp;
                    
var deleteID='<%=btndelete.ClientID%>';
                    window.document.all(deleteID).click();
                }

                event.cancelBubble
=true;                
            }

        
</ script >
    
</ HEAD >
    
< body >
        
< form  id ="Form1"  method ="post"  runat ="server" >
            
< TABLE  id ="Table1"  height ="100%"  cellSpacing ="1"  cellPadding ="1"  width ="100%"  border ="1" >
                
< tr  height ="30" >
                    
< td >< INPUT  id ="chkAll"  onclick ="chkAll_true()"  type ="checkbox" > 全选/取消 < asp:button  id ="btndelete"  runat ="server"  Text ="删除" ></ asp:button ></ td >
                
</ tr >
                
< TR  vAlign ="top" >
                    
< TD  width ="100%"  colSpan ="5" >< asp:datagrid  id ="DataGrid1"  runat ="server"  OnEditCommand ="Edit"  OnCancelCommand ="Cancel"  OnUpdateCommand ="Update"
                            DataKeyField
="UserID"  AutoGenerateColumns ="False"  AllowSorting ="True"  BorderColor ="Tan"  BorderWidth ="1px"  BackColor ="LightGoldenrodYellow"
                            CellPadding
="2"  GridLines ="None"  ForeColor ="Black"  OnDeleteCommand ="Delete" >
                            
< FooterStyle  BackColor ="Tan" ></ FooterStyle >
                            
< SelectedItemStyle  ForeColor ="GhostWhite"  BackColor ="DarkSlateBlue" ></ SelectedItemStyle >
                            
< AlternatingItemStyle  BackColor ="PaleGoldenrod" ></ AlternatingItemStyle >
                            
< HeaderStyle  Font-Bold ="True"  BackColor ="Tan" ></ HeaderStyle >
                            
< Columns >
                                
< asp:TemplateColumn  HeaderText ="序号" >
                                    
< ItemTemplate >
                                        
< INPUT  id =radio  onclick =fun_option(this)  type =radio  value ='<%#  DataBinder.Eval(Container.DataItem,"UserID") % > ' name=radio>
                                    
</ ItemTemplate >
                                    
< FooterTemplate >
                                    
</ FooterTemplate >
                                
</ asp:TemplateColumn >
                                
< asp:TemplateColumn  HeaderText ="序号" >
                                    
< FooterTemplate >
                                    
</ FooterTemplate >
                                
</ asp:TemplateColumn >
                                
< asp:TemplateColumn >
                                    
< ItemTemplate >
                                        
< INPUT  id ="chkExport"  type ="checkbox"  value ='<%#  DataBinder.Eval(Container.DataItem,"UserID") % > '>
                                    
</ ItemTemplate >
                                
</ asp:TemplateColumn >
                                
< asp:BoundColumn  DataField ="UserID"  SortExpression ="UserID"  ReadOnly ="True"  HeaderText ="UserID" ></ asp:BoundColumn >
                                
< asp:TemplateColumn  SortExpression ="UserName"  HeaderText ="姓名" >
                                    
< ItemTemplate >
                                        
< href ="http://singlepine.cnblogs.com/articles/266538.html"  target ="_blank" >
                                            
<% # DataBinder.Eval(Container.DataItem,"UserName" %>
                                        
</ a >
                                    
</ ItemTemplate >
                                    
< EditItemTemplate >
                                        
< asp:TextBox  id =UserName  Text ='<%#  DataBinder.Eval(Container.DataItem,"UserName") % > ' Width="88px" Runat="server">
                                        
</ asp:TextBox >
                                    
</ EditItemTemplate >
                                
</ asp:TemplateColumn >
                                
< asp:TemplateColumn  SortExpression ="province"  HeaderText ="省市" >
                                    
< ItemTemplate >
                                        
<% # DataBinder.Eval(Container.DataItem,"province" %>
                                    
</ ItemTemplate >
                                    
< EditItemTemplate >
                                        
< asp:DropDownList  id ="province"  Runat ="server"  AutoPostBack ="True"  OnSelectedIndexChanged ="ddlpovince_SelectedIndexChanged" ></ asp:DropDownList >
                                    
</ EditItemTemplate >
                                
</ asp:TemplateColumn >
                                
< asp:TemplateColumn  SortExpression ="city"  HeaderText ="县市" >
                                    
< ItemTemplate >
                                        
<% # DataBinder.Eval(Container.DataItem,"city" %>
                                    
</ ItemTemplate >
                                    
< EditItemTemplate >
                                        
< asp:DropDownList  id ="city"  Runat ="server" ></ asp:DropDownList >
                                    
</ EditItemTemplate >
                                
</ asp:TemplateColumn >
                                
< asp:TemplateColumn  SortExpression ="Enabled"  HeaderText ="可见否" >
                                    
< ItemTemplate >
                                        
<% # DataBinder.Eval(Container.DataItem,"Enabled" %>
                                    
</ ItemTemplate >
                                    
< EditItemTemplate >
                                        
< asp:CheckBox  id =chkenabled  Runat ="server"  Checked ='<%#  DataBinder.Eval(Container.DataItem,"Enabled") % > '>
                                        
</ asp:CheckBox >
                                    
</ EditItemTemplate >
                                
</ asp:TemplateColumn >
                                
< asp:EditCommandColumn  ButtonType ="PushButton"  UpdateText ="更新"  HeaderText ="编辑"  CancelText ="取消"  EditText ="编辑" ></ asp:EditCommandColumn >
                                
< asp:ButtonColumn  Text ="删除"  ButtonType ="PushButton"  HeaderText ="删除"  CommandName ="Delete" ></ asp:ButtonColumn >
                            
</ Columns >
                            
< PagerStyle  NextPageText ="下一页"  PrevPageText ="上一页"  HorizontalAlign ="Right"  ForeColor ="DarkSlateBlue"
                                BackColor
="PaleGoldenrod" ></ PagerStyle >
                        
</ asp:datagrid ></ TD >
                
</ TR >
                
< tr  height ="30" >
                    
< td ></ td >
                
</ tr >
            
</ TABLE >
            
< INPUT  id ="hiduserid"  type ="hidden"  runat ="server" >
        
</ form >
    
</ body >
</ HTML >
2.cs代码
public   class  DatagridTest : System.Web.UI.Page
    
{
        
protected System.Web.UI.WebControls.DataGrid DataGrid1;
        
protected System.Web.UI.HtmlControls.HtmlInputHidden hiduserid;
        
protected System.Web.UI.WebControls.Button btndelete;

        
private string constring="";
        
        
//目前功能:编辑、排序、单选项、复选项、合并单元格、产生序列号、联动下拉框、删除、超连接、鼠标移动改变颜色、奇偶项颜色区分
        private void Page_Load(object sender, System.EventArgs e)
        
{
            
if(!Page.IsPostBack)
            
{
                btndelete.Attributes.Add(
"onclick","Delete();");
                SortExpression
="";
                sort
="desc";
                DataBind();
            }
            
        }



        
DataBind

        
Web Form Designer generated code

        
GetDataSet
        
        
DataGrid1_ItemDataBound

        
DataGrid1_SortCommand

        
DataGrid1_ItemCreated

        
property

        
Edit

        
Cancel

        
Update

        
Delete event

        
ddlpovince_SelectedIndexChanged

        
btndelete_Click

        
delete
    }
3. 数据库教本(或下载真实数据 /Files/singlepine/area.rar)
if   exists  ( select   *   from  dbo.sysobjects  where  id  =   object_id (N ' [dbo].[TestGrid] ' and   OBJECTPROPERTY (id, N ' IsUserTable ' =   1 )
drop   table   [ dbo ] . [ TestGrid ]
GO

if   exists  ( select   *   from  dbo.sysobjects  where  id  =   object_id (N ' [dbo].[city] ' and   OBJECTPROPERTY (id, N ' IsUserTable ' =   1 )
drop   table   [ dbo ] . [ city ]
GO

if   exists  ( select   *   from  dbo.sysobjects  where  id  =   object_id (N ' [dbo].[povince] ' and   OBJECTPROPERTY (id, N ' IsUserTable ' =   1 )
drop   table   [ dbo ] . [ povince ]
GO

CREATE   TABLE   [ dbo ] . [ TestGrid ]  (
    
[ UserID ]   [ int ]   NOT   NULL  ,
    
[ UserName ]   [ nvarchar ]  ( 50 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
    
[ Country ]   [ nvarchar ]  ( 50 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
    
[ State ]   [ nvarchar ]  ( 50 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
    
[ Enabled ]   [ bit ]   NULL  
ON   [ PRIMARY ]
GO

CREATE   TABLE   [ dbo ] . [ city ]  (
    
[ id ]   [ int ]   NOT   NULL  ,
    
[ cityID ]   [ nvarchar ]  ( 6 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
    
[ city ]   [ nvarchar ]  ( 50 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
    
[ father ]   [ nvarchar ]  ( 6 ) COLLATE Chinese_PRC_CI_AS  NULL  
ON   [ PRIMARY ]
GO

CREATE   TABLE   [ dbo ] . [ povince ]  (
    
[ id ]   [ int ]   NOT   NULL  ,
    
[ provinceID ]   [ nvarchar ]  ( 6 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
    
[ province ]   [ nvarchar ]  ( 40 ) COLLATE Chinese_PRC_CI_AS  NULL  
ON   [ PRIMARY ]
GO
基于STM32F407,使用DFS算法实现最短迷宫路径检索,分为三种模式:1.DEBUG模式,2. 训练模式,3. 主程序模式 ,DEBUG模式主要分析bug,测量必要数据,训练模式用于DFS算法训练最短路径,并将最短路径以链表形式存储Flash, 主程序模式从Flash中….zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值