给按钮增加单击弹出确认框的功能是经常要用到的,我们一般是通过在RowDataBound事件里编码的方式实现,麻烦,所以扩展一下。
控件开发
1、新建一个继承自GridView的类。

/**////<summary>
///继承自GridView
///</summary>
[ToolboxData(@"<{0}:SmartGridViewrunat='server'></{0}:SmartGridView>")]
publicclassSmartGridView:GridView


{
}
2、新建一个ConfirmButton类,有两个属性

/**////<summary>
///ConfirmButton的摘要说明。
///</summary>
[ToolboxItem(false)]
[TypeConverter(typeof(ConfirmButtonConverter))]
publicclassConfirmButton


{
privatestring_commandName;

/**////<summary>
///按钮的CommandName
///</summary>
publicstringCommandName


{

get
{returnthis._commandName;}

set
{this._commandName=value;}
}

privatestring_confirmMessage;

/**////<summary>
///确认框弹出的信息
///</summary>
publicstringConfirmMessage


{

get
{returnthis._confirmMessage;}

set
{this._confirmMessage=value;}
}
}
3、新建一个继承自CollectionBase的类ConfirmButtons

/**////<summary>
///ProjectGroups的摘要说明。
///注意要继承自CollectionBase
///</summary>
[
ToolboxItem(false),
ParseChildren(true)
]
publicclassConfirmButtons:CollectionBase


{

/**////<summary>
///构造函数
///</summary>
publicConfirmButtons()
:base()


{
}


/**////<summary>
///实现IList接口
///获取或设置指定索引处的元素。
///</summary>
///<paramname="index">要获得或设置的元素从零开始的索引</param>
///<returns></returns>
publicConfirmButtonthis[intindex]


{
get


{
return(ConfirmButton)base.List[index];
}
set


{
base.List[index]=(ConfirmButton)value;
}
}


/**////<summary>
///实现IList接口
///将某项添加到System.Collections.IList中。
///</summary>
///<paramname="item">要添加到System.Collections.IList的System.Object。</param>
publicvoidAdd(ConfirmButtonitem)


{
base.List.Add(item);
}


/**////<summary>
///实现IList接口
///从System.Collections.IList中移除特定对象的第一个匹配项。
///</summary>
///<paramname="index">要从System.Collections.IList移除的System.Object</param>
publicvoidRemove(intindex)


{
if(index>-1&&index<base.Count)


{
base.List.RemoveAt(index);
}
}
}
4、新建一个继承自ExpandableObjectConverter的类ConfirmButtonConverter

/**////<summary>
///类型转换器
///</summary>
publicclassConfirmButtonConverter:ExpandableObjectConverter


{

/**////<summary>
///返回值能否将ConfirmButton类型转换为String类型
///</summary>
///<paramname="context"></param>
///<paramname="destinationType"></param>
///<returns></returns>
publicoverrideboolCanConvertTo(ITypeDescriptorContextcontext,TypedestinationType)


{
if(destinationType==typeof(string))


{
returntrue;
}
returnbase.CanConvertTo(context,destinationType);
}


/**////<summary>
///将ConfirmButton类型转换为String类型
///</summary>
///<paramname="context"></param>
///<paramname="culture"></param>
///<paramname="value"></param>
///<paramname="destinationType"></param>
///<returns></returns>
publicoverrideobjectConvertTo(ITypeDescriptorContextcontext,CultureInfoculture,
objectvalue,TypedestinationType)


{
if(value!=null)


{
if(!(valueisYYControls.SmartGridView.ConfirmButton))


{
thrownewArgumentException(
"无效的ConfirmButton","value");
}
}

if(destinationType.Equals(typeof(string)))


{
if(value==null)


{
returnString.Empty;
}
return"ConfirmButton";
}
returnbase.ConvertTo(context,culture,value,destinationType);
}
}
5、在继承自GridView的类中加一个复杂对象属性,该复杂对象就是第3步创建的那个ConfirmButtons
privateConfirmButtons_confirmButtons;

/**////<summary>
///确认按钮集合
///</summary>
[
PersistenceMode(PersistenceMode.InnerProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Description("确认按钮集合,确认按钮的CommandName和提示信息"),
Category("扩展")
]
publicvirtualConfirmButtonsConfirmButtons


{
get


{
if(_confirmButtons==null)


{
_confirmButtons=newConfirmButtons();
}
return_confirmButtons;
}
}
6、重写OnRowDataBound实现单击命令按钮弹出确认框的功能。主要是给按钮增加一个客户端的onclick事件。
相关推荐
3、单击命令按钮弹出确认框 设置其ConfirmButtons属性 CommandName - 命令按钮的CommandName属性 ConfirmMessage - 弹出的确认框所显示的文字 4、每行复选框的全选与取消全选 在模板列的头模板处添加一个复选框...
* 监听 GridView 控件的事件,例如单击“删除”按钮时,弹出“确认删除此信息?”的提示信息。 * 使用 JavaScript 和 ASP.NET 服务器控件来实现客户端和服务器端的交互。 本节学习内容涵盖了 GridView 控件的使用、...
当用户在弹出的`div`中完成编辑并点击保存按钮后,需要将修改后的数据发送回服务器,以便更新数据库并刷新`GridView`中的数据。这可以通过Ajax异步请求实现,确保页面不会重新加载,保持良好的用户体验。 综上所述...
删除GridView控件行信息弹出确认提示框 **7.1 CommandField列** 使用`CommandField`列来添加命令按钮,例如编辑、删除等。可以自定义按钮的文本和图像,也可以添加JavaScript确认框。 **7.2 前台界面** 界面应...
7. **删除时弹出确认对话框**:在删除操作前显示确认对话框,防止误操作。 8. **自动编号**:为每一行数据添加序列号,可以使用模板列并在RowDataBound事件中实现。 9. **自定义时间货币等字符串格式**:在...
在新闻显示页面,添加一个字段“删除”,运行时,单击该行的“删除按钮时”,弹出“确认删除此信息?”的提示信息,当按确定按钮时删除该行的信息,按取消按钮时不执行删除操作。 首先我们先进行一个知识点归纳: ...
在ASP.NET Web应用程序中,GridView控件是一种常用的数据展示组件,它可以轻松地绑定到数据源并展示数据。本文将深入探讨GridView的各种使用方法,包括代码分页、保存和恢复CheckBox的状态、排序、与DropDownList和...
0452 单击GridView控件按钮刷新保持原来的位置 253 0453 向GridView Web控件中添加CheckBox控件 253 0454 如何使用GridView Web控件实现超级链接 254 0455 在GridView Web控件中高亮显示鼠标所在行 256 0456...
在编辑模式下,单击某一项时,可以弹出确认删除的对话框,或者直接执行删除操作。同时,单击事件也可以用于退出编辑模式,恢复GridView的正常显示状态。 4. 数据操作 删除项时,需要更新适配器中的数据源(如...
8. **实现删除时弹出确认对话框**:在`RowDeleting`事件中添加确认对话框代码,确保用户确认删除操作。 9. **实现自动编号**:可以创建一个自定义的`BoundField`或使用`TemplateField`,在`RowDataBound`事件中动态...
GridView实现删除时弹出确认对话框 在删除操作前显示一个确认对话框可以避免意外删除数据。可以使用JavaScript来实现这个功能。 ```csharp protected void GridView1_RowDeleting(object sender, ...
删除时弹出确认对话框 在`RowDeleting`事件中,可以添加一个JavaScript确认对话框,确保用户在删除前做出确认。 ### 8. 自动编号 可通过添加一个额外的BoundField,设置其数据源为行索引,实现自动编号。 ### 9. ...
28. 数据删除确认:在删除操作前弹出确认对话框,增加用户操作的安全性。 29. 数据绑定表达式:使用DataBinder.Eval或Container.DataItem属性,动态绑定数据到控件。 30. 空数据提示:当数据为空时,显示自定义...
7. **实现删除时弹出确认对话框**: - 使用JavaScript或jQuery的确认对话框,确保用户在删除前确认操作。 8. **自动编号**: - 自定义一个模板字段,结合`RowDataBound`事件,为每行生成连续的编号。 9. **...
2. 在弹出的控件列表中,找到MSFlexGrid并添加到对话框上。 3. 生成对应的成员变量,并在代码中通过这些变量控制控件的行为。 **5. 编程接口** MSFlexGrid控件提供了丰富的API接口,如`SetRow`和`SetCol`用于定位...
- **定义**: `Popup` 控件用于创建弹出窗口。 - **示例**: - 对 `Popup` 进行动画处理。 - 指定自定义 `Popup` 位置。 #### ProgressBar - **定义**: `ProgressBar` 控件用于指示操作的进度。 - **用途**: 显示...
- **在标题获得单击时对GridView列进行排序**:响应用户的交互操作。 - **创建ListView的自定义视图模式**:通过继承`ListViewBase`并重写相应方法。 - **使用模板来设置使用GridView的ListView的样式**:实现...
在GridControl中,默认情况下单击列头会弹出一个右键菜单。如果希望禁用这一特性,可以将`RunDesign->OptionsMenu->EnableColumnMenu`属性设置为`false`。 6. **隐藏GroupPanel表头** GroupPanel是GridControl中...