GridView的 OnRowDataBound 事件用法
<asp:GridView ID="RptUsers" runat="server" AutoGenerateColumns="False" Width="99%"
CssClass="data_table" AllowPaging="false" OnPageIndexChanging="RptUsers_PageIndexChanging"
OnRowCommand="RptUsers_RowCommand" onrowdatabound="RptUsers_RowDataBound" >
<AlternatingRowStyle BackColor="#fafafa" />
<EmptyDataRowStyle HorizontalAlign="Left" />
<PagerStyle HorizontalAlign="left" />
<RowStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
<Columns>
<asp:TemplateField HeaderText="选择" Visible="false" HeaderStyle-Wrap="false">
<HeaderTemplate>
<input id="cbSelAll" onclick="SelectedAllChk(this.checked);" type="checkbox">
</HeaderTemplate>
<ItemTemplate>
<%#GetInputTagHtml(Convert.ToInt32(Eval("Id")))%>
<asp:HiddenField ID="HFId" runat="server" Value='<%# Eval("Id") %>' />
</ItemTemplate>
<ItemStyle Wrap="False" HorizontalAlign="left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="序号" HeaderStyle-Wrap="false">
<ItemTemplate>
<%# (this.AspNetPager1.CurrentPageIndex - ) * this.AspNetPager1.PageSize + Container.DataItemIndex + %>
</ItemTemplate>
<ItemStyle Wrap="False" HorizontalAlign="left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="投票名称" HeaderStyle-Wrap="false">
<ItemTemplate>
<%#Eval("Name")%>
</ItemTemplate>
<ItemStyle Wrap="true" HorizontalAlign="left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="主办单位" HeaderStyle-Wrap="false">
<ItemTemplate>
<%# Eval("Organizer")%>
</ItemTemplate>
<ItemStyle Wrap="true" HorizontalAlign="left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="创建者" HeaderStyle-Wrap="false">
<ItemTemplate>
<%#GetUserName(Convert.ToInt32(Eval("Creater")))%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="开始时间" HeaderStyle-Wrap="false">
<ItemTemplate>
<%# GetDateStr(Eval("StartTime").ToString()) %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="结束时间" HeaderStyle-Wrap="false">
<ItemTemplate>
<%# GetDateStr(Eval("EndTime").ToString())%>
</ItemTemplate>
<ItemStyle Wrap="False" HorizontalAlign="left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="创建时间" HeaderStyle-Wrap="false">
<ItemTemplate>
<%#Convert.ToDateTime(Eval("CreateTime").ToString()).ToString("yyyy-MM-dd")%>
</ItemTemplate>
<ItemStyle Wrap="False" HorizontalAlign="left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="投票类型" HeaderStyle-Wrap="false">
<ItemTemplate>
<%#GetActiveType(Eval("ActiveType").ToString())%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="投票IP限制" HeaderStyle-Wrap="false">
<ItemTemplate>
<%#GetIPLimitType(Eval("IPLimitType").ToString())%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="游客投票" HeaderStyle-Wrap="false">
<ItemTemplate>
<%#GetUserLimitType(Eval("UserLimitType").ToString())%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="开启状态" HeaderStyle-Wrap="false">
<ItemTemplate>
<%# GetStateStr(Eval("States").ToString())%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="操作" HeaderStyle-Wrap="false">
<ItemTemplate>
<%# GetOperateStr(Eval("ActiveType").ToString(), Eval("Id").ToString())%>
<a href='/admin/ActivityInfo/ActivityInfoAdd.aspx?action=edit&id=<%#Eval("Id") %>'>编辑</a>
<asp:LinkButton ID="lkbtnOpen" CommandName="lkbtnOpen" runat="server" CommandArgument='<%# Eval("Id") %>'>开启</asp:LinkButton>
<asp:HiddenField ID="hid_states" runat="server" Value='<%# Eval("States") %>' />
<asp:LinkButton ID="lkbtnVote" CommandName="lkbtnVote" runat="server" CommandArgument='<%# Eval("Id") %>'>投票数据同步</asp:LinkButton>
<asp:LinkButton ID="lkbDelete" CommandName="lkbDelete" runat="server" CommandArgument='<%# Eval("Id") %>' OnClientClick="return confirm('您将清除此投票项目的投票数据,确认删除吗?');">删除</asp:LinkButton>
<a href="javascript:void(0)" onclick="manageWorkVoteInfo(<%#Eval("Id") %>)">投票统计</a>
</ItemTemplate>
<ItemStyle Wrap="False" HorizontalAlign="left" />
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<img src="/images/no_data.gif" />
</EmptyDataTemplate>
</asp:GridView>
protected void RptUsers_RowCommand(object sender, GridViewCommandEventArgs e)
{
//删除
if (e.CommandName.Equals("lkbDelete"))
{
try
{
Dictionary<string, object> searchConditions = new Dictionary<string, object>();
searchConditions.Add("States",);
searchConditions.Add("ActivityId", Convert.ToInt32(e.CommandArgument.ToString())); IList<WorkInfo> workInfo_list = ServiceFactory.WorkInfoService.QueryWorkInfo(searchConditions);
if (workInfo_list.Count > )
{
JSUtil.MessageBox("该投票下面有图文作品,请先删除图片作品!");
return;
} ActivityInfo model_activeInfo = ServiceFactory.ActivityInfoService.GetById(Convert.ToInt32(e.CommandArgument.ToString()));
string imgpath =model_activeInfo==null?"": model_activeInfo.ImgPath;
ActivityInfo activity = model_activeInfo;
//ServiceFactory.ActivityInfoService.Delete(Convert.ToInt32(e.CommandArgument.ToString()));
IOHelper.DeleteFile(Server.MapPath(imgpath));
UserInfo user=ServiceFactory.UserInfoService.GetById(int.Parse(activity.Creater));
IDictionary<string, object> param = new Dictionary<string, object>();
param.Add("Activity", activity.Id);
param.Add("AdminId", user.Id);
//投票活动和管理员授权列表
IList<RelationAdminActivityInfo> res = ServiceFactory.RelationAdminActivityInfoService.QueryConditions(param);
if (res != null && res.Count > )
{
foreach(var item in res)
{
ServiceFactory.RelationAdminActivityInfoService.Delete(item.Id);
}
}
//删除投票活动 20161216
ServiceFactory.ActivityInfoService.Delete(Convert.ToInt32(e.CommandArgument.ToString())); JSUtil.MessageBox("删除成功!");
BindData();
}
catch
{
JSUtil.MessageBox("删除失败,请稍后再试!");
}
}
//投票同步
else if (e.CommandName.Equals("lkbtnVote"))//作品数和投票数数据同步
{
try
{
int votecount = ;
ActivityInfo activity = ServiceFactory.ActivityInfoService.GetById(int.Parse(e.CommandArgument.ToString()));
//图文投票
if (activity.ActiveType == )
{
Dictionary<string, object> searchConditions = new Dictionary<string, object>();
searchConditions.Add("States", );
searchConditions.Add("ActivityId", Convert.ToInt32(e.CommandArgument.ToString()));
IList<WorkInfo> workInfo_list = ServiceFactory.WorkInfoService.QueryWorkInfo(searchConditions);
if (workInfo_list != null && workInfo_list.Count > )
{
for (int i = ; i < workInfo_list.Count; i++)
{
votecount += workInfo_list[i].TotalVoteCount;
}
}
activity.VoteCount = votecount; //投票数
activity.WorkCount = workInfo_list.Count;//作品数
ServiceFactory.ActivityInfoService.Update(activity);
}
else //文字投票 ToDo
{
}
JSUtil.MessageBox("同步成功!");
BindData();
}
catch
{
JSUtil.MessageBox("同步失败,请稍后再试!");
}
} //开启
else if (e.CommandName.Equals("lkbtnOpen"))//开启
{
try
{
ActivityInfo activity = ServiceFactory.ActivityInfoService.GetById(int.Parse(e.CommandArgument.ToString()));
if (activity.States == )
{
activity.States = ;
activity.UpdateTime = DateTime.Now;
}
else
{
activity.States = ;
activity.UpdateTime = DateTime.Now;
}
ServiceFactory.ActivityInfoService.Update(activity);
JSUtil.MessageBox("操作成功!");
BindData();
}
catch
{
JSUtil.MessageBox("操作失败,请稍后再试!");
}
}
}
protected void RptUsers_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//用FindControl方法找到模板中的Label控件
HiddenField HiddenField = (HiddenField)e.Row.FindControl("hid_states");// 0不开启 1 开启
LinkButton lkbtnOpen = (LinkButton)e.Row.FindControl("lkbtnOpen"); //开启按钮
if (HiddenField.Value == "")
{
lkbtnOpen.Text = "开启";
}
else
{
lkbtnOpen.Text = "关闭";
}
}
}
GridView的 OnRowDataBound 事件用法的更多相关文章
- GridView的 PreRender事件与 RowCreated、RowDataBound事件大乱斗
GridView的 PreRender事件与 RowCreated.RowDataBound事件大乱斗 之前写了几个范例,做了GridView的 PreRender事件与 RowCreated.Row ...
- jQuery 事件用法详解
jQuery 事件用法详解 目录 简介 实现原理 事件操作 绑定事件 解除事件 触发事件 事件委托 事件操作进阶 阻止默认事件 阻止事件传播 阻止事件向后执行 命名空间 自定义事件 事件队列 jque ...
- 网格视图(GridView)功能和用法
GridView用于在界面上按行.列分布的方式来显示多个组件.GridView和ListView有共同的父类:AbsListView,因此GridView和ListView具有很高的相似性,它们都是列 ...
- jQuery event,冒泡,默认事件用法
jQuery event,冒泡,默认事件用法 <%@ page language="java" import="java.util.*" pageEnco ...
- 【DevExpress】GridView的RowClick事件禁用Checkbox选择的解决办法
添加GridView的RowCellClick事件,代码如下 private void gvBoxMails_RowCellClick(object sender, DevExpress.XtraGr ...
- repeater的command事件用法
当Repeater里面循环控件时就会用到command, 是Repeater控件的原生事件用法 Repeater里面如果循环控件,控件的ID是会被改变的 repeater.itemcommand+= ...
- jquery get ($.get) 事件用法与分析
jquery get ($.get) 事件用法与分析 get() 方法通过远程 HTTP GET 请求载入信息.这是一个简单的 GET 请求功能以取代复杂 $.ajax .请求成功时可调用回调函数.如 ...
- GridView的 PreRender事件与范例--GridView + CheckBox,点选多列资料(复选删除)
GridView的 PreRender事件与范例--GridView + CheckBox,点选多列资料(复选删除) 之前有一个范例,相同的结果可以用两种作法来实践 [GridView] 资料系结表达 ...
- 关于gridview里加按钮事件的总结
1. onrowcommand="GridView1_RowCommand1" 在gridview申明时的属性里要有,然后找到闪电,双击 还有要把那个按钮行模板化,就是箭头里面的t ...
随机推荐
- MySQL 优化之 Linux系统层面调优
MySQL 一般运行于Linux系统中.对于MySQL的调优一般分为Linux操作系统层面的调优和MySQL层面的调优(当然还有架构层面.业务层面.应用程序层面的调优).操作系统主要是管理和分配硬件资 ...
- Windows7 系统 CMD命令行,点阵字体不能改变大小以及中文乱码的问题
之前装了oracle 11g后,发现开机速度竟然奇葩的达到了3分钟.经过旁边大神指点,说是因为oracle某个(具体不清楚)服务,在断网的时候会不断的ping网络,导致速度变慢.然后就关服务呗,然后一 ...
- linux系统的任务计划crontab使用详解
linux系统的任务计划crontab使用详解 其实大部分系统管理工作都是通过定期自动执行某一个脚本来完成的,那么如何定期执行某一个脚本呢?这就要借助linux的cron功能了. 关于cron任务计划 ...
- Struts2文件上传,以及各种注意事项
首先肯定是要配置好struts2环境,这个在另一篇<struts2环境搭建,以及一个简单实例>里已经讲过了 首先是网页部分,upload_file.jsp <%@ page lang ...
- ajax小结
1. http是一种无状态协议 2. http请求:四部分组成 ① http 请求的方法或动作,如:GET / POST ② 正在请求的URL,总得知道请求的地址是什么 ③ 请求头,包含一些客户端环境 ...
- Android中关于Handler的若干思考
在之前的博文中,讲过一些和Handler有关的知识,例如: Android 多线程----AsyncTask异步任务详解 Android多线程----异步消息处理机制之Handler详解 今天再把Ha ...
- nginx 入门
1.nginx 如何处理一个请求 IP,域名的处理 server { listen 80 default_server; //添加 default_server就是一个默认的server ...
- php一句话后门过狗姿势万千之传输层加工【三】
既然木马已就绪,那么想要利用木马,必然有一个数据传输的过程,数据提交是必须的,数据返回一般也会有的,除非执行特殊命令. 当我们用普通菜刀连接后门时,数据时如何提交的,狗狗又是如何识别的,下面结合一个实 ...
- bzoj3223 文艺平衡树 (treap or splay分裂+合并)
3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 3313 Solved: 1883 [Submit][S ...
- 一个简单的socket程序运行与抓包查看
为了熟悉socket编程,在ubuntu下运行了一个现有例子(Networking and Socket programming tutorial in C - CodeProject),并通过抓包查 ...