asp.net2.0的几个标准控件使用的小技巧

简介:

给自己留个记录
1.给删除按钮添加个确认页面
给普通的button按钮和LinkButton增加个确认窗口,只要在他们的OnClickClient属性里写上“return confirm('是否确认删除这个项目?');”就可以了。在GridView和DetailsView控件的TemplateField里添加个delete按钮,也可以用相同的方法实现,但如果使用DetailsView的AutoGenerateDeleteButton="True"生成出来的删除按钮要怎么增加这个确认窗口?因为我们不能在设计窗口里设置自动生成的删除按钮的属性,在网上找了一圈 找到一个方法:
在DetailsView的ItemCreated的事件里写上以下代码

None.gif     protected   void  DetailsViewTips_ItemCreated( object  sender, EventArgs e)
ExpandedBlockStart.gif    
{
InBlock.gif        
// Test FooterRow to make sure all rows have been created 
InBlock.gif
        if (DetailsViewTips.FooterRow != null)
ExpandedSubBlockStart.gif        
{
InBlock.gif            
// The command bar is the last element in the Rows collection
InBlock.gif
            int commandRowIndex = DetailsViewTips.Rows.Count - 1;
InBlock.gif            DetailsViewRow commandRow 
= DetailsViewTips.Rows[commandRowIndex];
InBlock.gif
InBlock.gif            
// Look for the DELETE button
InBlock.gif
            DataControlFieldCell cell = (DataControlFieldCell)commandRow.Controls[0];
InBlock.gif            
foreach (Control ctl in cell.Controls)
ExpandedSubBlockStart.gif            
{
InBlock.gif                LinkButton link 
= ctl as LinkButton;
InBlock.gif                
if (link != null)
ExpandedSubBlockStart.gif                
{
InBlock.gif                    
if (link.CommandName.ToLower() == "delete")
ExpandedSubBlockStart.gif                    
{
InBlock.gif                        link.ToolTip 
= "Click here to delete";
InBlock.gif                        link.OnClientClick 
= "return confirm('Do you really want to delete this record?');";
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

2.GridView的分页
如果Gridview里指定了DataSourceID,那你什么都不用做,所有的分页和排序都能很好的自己实现。但如果是自己使用Gridview.DataSource=source;Gridview.databind();来自己绑定,那你不得不自己实现GridView的PageIndexChanging事件,代码大致是这样的
None.gif      protected   void  GridViewEditor_PageIndexChanging( object  sender, GridViewPageEventArgs e)
ExpandedBlockStart.gif    
{
InBlock.gif            DataTable source
=dot.gif..;
InBlock.gif            GridView.DataSource 
= source;
InBlock.gif            GridView.PageIndex 
=e.NewPageIndex;
InBlock.gif            GridView.DataBind();
ExpandedBlockEnd.gif    }

3.DetailsView的编辑时的控件验证
要使用到验证控件,DetailsView里的只能在他的TemplateField里,而且每个TemplateField里的验证控件也只能找到相同TemplateField里的TextBox等控件,如果想夸Field验证,只能使用CustomValidator控件,然后再实现它的CustomValidator1_ServerValidate事件 类似代码如下:
None.gif      protected   void  CustomValidator1_ServerValidate( object  source, ServerValidateEventArgs args)
ExpandedBlockStart.gif    
{
InBlock.gif        TextBox tb 
= (TextBox)DetailsViewEditor.FindControl("TextBoxGPsw");
InBlock.gif        
string psw1 = tb.Text;
InBlock.gif        tb 
= (TextBox)DetailsViewEditor.FindControl("TextBoxPassword");
InBlock.gif        
string psw2 = tb.Text;
InBlock.gif        
if (psw1==psw2)
ExpandedSubBlockStart.gif        
{
InBlock.gif            args.IsValid 
= true;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gif        
{
InBlock.gif            args.IsValid 
= false;
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

路漫漫其修远兮 吾将上下而求索

my blog

本文转自 lu xu 博客园博客,原文链接:http://www.cnblogs.com/dotLive/archive/2007/02/04/639277.html    ,如需转载请自行联系原作者
相关文章
|
2月前
|
SQL 开发框架 前端开发
ASP.NET WEB项目中GridView与Repeater数据绑定控件的用法
ASP.NET WEB项目中GridView与Repeater数据绑定控件的用法
32 0
|
3月前
|
SQL 开发框架 JavaScript
分享33个ASP.NET电子商务源码和40个ASP.NET控件组件源码,总有一款适合您
分享33个ASP.NET电子商务源码和40个ASP.NET控件组件源码,总有一款适合您
29 0
|
4月前
|
JavaScript C#
【傻瓜级JS-DLL-WINCC-PLC交互】2.wincc使用C#开发的.net控件
【傻瓜级JS-DLL-WINCC-PLC交互】2.wincc使用C#开发的.net控件
41 0
|
4月前
|
JavaScript Linux C#
【傻瓜级JS-DLL-WINCC-PLC交互】1.C#用windows窗体控件创建.net控件
【傻瓜级JS-DLL-WINCC-PLC交互】1.C#用windows窗体控件创建.net控件
65 0
|
4月前
|
开发框架 .NET 数据安全/隐私保护
Asp.Net第二章服务器端控件
Asp.Net第二章服务器端控件
27 0
|
4月前
|
开发框架 JavaScript .NET
Asp.Net就业课之三验证控件
Asp.Net就业课之三验证控件
44 0
|
4月前
|
开发框架 .NET
Asp.Net就业课堂之模板控件
Asp.Net就业课堂之模板控件
38 1
|
前端开发 JavaScript .NET
NET中验证控件表达式汇总
ASP.NET为开发人员提供了一整套完整的服务器控件来验证用户输入的信息是否有效。这些控件如下:     1、RequiredFieldValidator:验证一个必填字段,如果这个字段没填,那么,将不能提交信息。
968 0
|
3月前
|
开发框架 前端开发 .NET
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
38 0
|
30天前
|
开发框架 前端开发 .NET
进入ASP .net mvc的世界
进入ASP .net mvc的世界
28 0