zoukankan
html css js c++ java
GridView技巧之改变行的背景颜色和删除确认对话框
有时候我们希望当鼠标停在某一行时改变该行的背景颜色,还有就是当删除某一行时弹出确认对话框。我这里的删除弹出确认对话框是用LinkButton实现的,我知道在GridView里可以用自带的删除实现,但是总觉的他自带的有些不好用,呵呵,也许是我不会用。
好了,下面就是我实现的代码,都运行过,没有错误。
/**/
///
<summary>
///
设置gridview的行,如删除时弹出确认对话框,还有设置鼠标停在行上时设置背景颜色
///
</summary>
///
<param name="gridview"></param>
///
<param name="bgcolor">
有默认值
</param>
///
<param name="bgflag">
true表示设置背景颜色
</param>
public
void
SetGridViewDeleleteAndBackgroundColor(GridView gridview,
string
bgcolor,
bool
bgflag)
{
if
(bgcolor
==
""
)
bgcolor
=
"
#EAEAEA
"
;
//
如果参数为空,则设置一个默认值
for
(
int
i
=
0
; i
<
gridview.Rows.Count; i
++
)
{
((LinkButton)gridview.Rows[i].FindControl(
"
LinkButtonDelete
"
)).Attributes.Add(
"
onclick
"
,
"
if(!confirm('您确认要执行吗?')) return false;
"
);
if
(bgflag)
//
如果为true,表示要起用该功能
{
//
设置鼠标移动到行上的颜色
if
(gridview.Rows[i].RowType
==
DataControlRowType.DataRow)
//
要先判断是否为gridview的数据行
{
gridview.Rows[i].Attributes.Add(
"
onmouseover
"
,
"
cl=this.style.backgroundColor;this.style.backgroundColor=
'"+bgcolor+"'
;
"
);
//
cl为保存先前的颜色,方便稍后恢复,要在前台定义变量哦。
gridview.Rows[i].Attributes.Add(
"
onmouseout
"
,
"
this.style.backgroundColor=cl;
"
);
}
}
}
}
这里用的就是Attributes属性,其实这个属性几乎所有的服务器控件都有,就是用来设置客户端的操作,我经常用这个属性。调用该函数的代码就不用写了吧,太简单了。下面的时件中有。
下面是LinkButton的删除事件:
protected
void
LinkButtonDelete_Click(
object
sender, EventArgs e)
{
int
archivesid
=
Int32.Parse(((LinkButton)sender).CommandArgument.Trim());
//
获取要删除的档案ID,这个值在数据源绑定时已经设置好的。
ArchivesBLL archives
=
new
ArchivesBLL();
archives.DeleteArchive(archivesid);
//
调用逻辑层方法,可参考我的另一篇文章三层架构方法调用
//
刷新列表
DataTable dt
=
new
DataTable();
dt
=
archives.SelectArchivesAll();
//
调用逻辑层方法
this
.GridView1.DataSource
=
dt;
this
.GridView1.DataBind();
new
OASBasicBLL().
SetGridViewDeleleteAndBackgroundColor(this.GridView1, "", true);
//
调用刚刚前面的那个函数
}
查看全文
相关阅读:
WeChat-SmallProgram:组件 scroll-view 横向和纵向 案例
Codeforces Round #277 (Div. 2) D. Valid Sets 树形DP
Codeforces Round #243 (Div. 2) E. Sereja and Two Sequences DP
Codeforces Round #263 (Div. 2) D. Appleman and Tree 树形dp
Codeforces Round #259 (Div. 2) D. Little Pony and Harmony Chest 状压DP
Codeforces Round #274 (Div. 2) E. Riding in a Lift DP
HDOJ 6069 素数筛
在平面中,一个点绕任意点旋转θ度后的点的坐标
HDOJ 5724 博弈SG函数
Codeforces Round #422 (Div. 2) C. Hacker, pack your bags! 排序+贪心
原文地址:https://www.cnblogs.com/ringwang/p/993531.html
最新文章
合并石子 四边形不等式优化
最小代价
Git报错:remote: Incorrect username or password ( access token )
Android Studio报错:failed to notify build listener.
AnroidStudio中导入module步骤
AndroidStudio报错: Cannot find a version of 'com.android.support:support-annotations'
Android第三方模拟器_夜神模拟器安装教程
消息中间件_ActiveMQ_Linux下安装
消息中间件_ActiveMQ消息类型
消息中间件_ActiveMQ入门教程
热门文章
Git 1.9.4 clone报错:fatal unable to access 'https://xxxx':error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
rabbitmq++:RabbitMQ的消息确认ACK机制介绍
coding++:java-HashMap的负载因子为什么默认是0.75?
coding++:Spring_IOC(控制反转)详解
coding++:事务管理 隔离级别
coding++:TransactionDefinition 接口介绍
coding++:mybatis update foreach (SQL循环)批量更新
WeChat-SmallProgram:引用页面调用组件内的方法
WeChat-SmallProgram:自定义select下拉选项框组件
WeChat-SmallProgram:如何定义一个组件
Copyright © 2011-2022 走看看