在gridview控件中当鼠标滑动时,光标所在行颜色改变,第一列加了一个删除图标按钮,当点击删除图标时提示是否删除,但是第一行不能正常能正常操作,鼠表停留在第一行颜色不变,点击删除按钮时也不提示,而其它各行都正常。
页面代码如下: <asp:gridview id="flow_mainGrid" runat="server" allowpaging="true" allowsorting="true"
autogeneratecolumns="false" PageSize ="5" cellpadding="3" OnPageIndexChanging ="flow_mainGrid_pageindexchanging" OnSorting="flow_mainGrid_sorting" forecolor="#333333" gridlines="none"
width="100%" datakeynames="flow_id" style="font-size: 12px; font-family: 宋体" OnRowDataBound="flow_mainGrid_RowDataBound">
<footerstyle backcolor="#990000" font-bold="true" forecolor="white" Width="400px" />
<columns>
<asp:TemplateField HeaderText="删除">
<ItemTemplate>
<asp:ImageButton ID="delFlowmain" runat="server" ImageUrl="~/images/del.gif" />
</ItemTemplate>
</asp:TemplateField>
<asp:boundfield datafield="title" headertext="标题" readonly="true" />
<asp:boundfield datafield="describe" headertext="事宜描述" readonly="true" />
<asp:boundfield datafield="out_dep_name" headertext="提出部门" readonly="true" />
<asp:boundfield datafield="out_user_name" headertext="提出人" sortexpression="out_user_name" />
<asp:boundfield datafield="out_time" headertext="发出时间" HtmlEncode = "false" DataFormatString="{0:yyyy-MM-dd}" sortexpression="out_time" />
<asp:boundfield datafield="in_dep_name" headertext="受理部门" sortexpression="in_dep_name" />
<asp:boundfield datafield="in_user_name" headertext="受理人" sortexpression="in_dep_name" />
</columns>
<rowstyle backcolor="#fffbd6" forecolor="#333333" />
<selectedrowstyle backcolor="#ffcc66" font-bold="true" forecolor="navy" />
<pagerstyle backcolor="#ffcc66" forecolor="#333333" horizontalalign="center" />
<headerstyle backcolor="#990000" font-bold="true" forecolor="white" />
<alternatingrowstyle backcolor="white" />
</asp:gridview>后台:
protected void flow_mainGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i;
//执行循环,保证每条数据都可以更新
for (i = 0; i < flow_mainGrid.Rows.Count; i++)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
((ImageButton)e.Row.Cells[0].FindControl("delFlowmain")).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
}
}
}
页面代码如下: <asp:gridview id="flow_mainGrid" runat="server" allowpaging="true" allowsorting="true"
autogeneratecolumns="false" PageSize ="5" cellpadding="3" OnPageIndexChanging ="flow_mainGrid_pageindexchanging" OnSorting="flow_mainGrid_sorting" forecolor="#333333" gridlines="none"
width="100%" datakeynames="flow_id" style="font-size: 12px; font-family: 宋体" OnRowDataBound="flow_mainGrid_RowDataBound">
<footerstyle backcolor="#990000" font-bold="true" forecolor="white" Width="400px" />
<columns>
<asp:TemplateField HeaderText="删除">
<ItemTemplate>
<asp:ImageButton ID="delFlowmain" runat="server" ImageUrl="~/images/del.gif" />
</ItemTemplate>
</asp:TemplateField>
<asp:boundfield datafield="title" headertext="标题" readonly="true" />
<asp:boundfield datafield="describe" headertext="事宜描述" readonly="true" />
<asp:boundfield datafield="out_dep_name" headertext="提出部门" readonly="true" />
<asp:boundfield datafield="out_user_name" headertext="提出人" sortexpression="out_user_name" />
<asp:boundfield datafield="out_time" headertext="发出时间" HtmlEncode = "false" DataFormatString="{0:yyyy-MM-dd}" sortexpression="out_time" />
<asp:boundfield datafield="in_dep_name" headertext="受理部门" sortexpression="in_dep_name" />
<asp:boundfield datafield="in_user_name" headertext="受理人" sortexpression="in_dep_name" />
</columns>
<rowstyle backcolor="#fffbd6" forecolor="#333333" />
<selectedrowstyle backcolor="#ffcc66" font-bold="true" forecolor="navy" />
<pagerstyle backcolor="#ffcc66" forecolor="#333333" horizontalalign="center" />
<headerstyle backcolor="#990000" font-bold="true" forecolor="white" />
<alternatingrowstyle backcolor="white" />
</asp:gridview>后台:
protected void flow_mainGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i;
//执行循环,保证每条数据都可以更新
for (i = 0; i < flow_mainGrid.Rows.Count; i++)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
((ImageButton)e.Row.Cells[0].FindControl("delFlowmain")).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
}
}
}
解决方案 »
- GridView中显示详细信息
- 急急,怎样通过“接口”将“对象”(类)发布出去
- 关于Microsoft.com NewsBar想到的一个问题
- 请问datagrid表里的列可以固定宽度吗?怎样固定?
- 孟子大哥请进,请教"基于角色(Role-Based)的表单验证"的问题.不会的也进来学习一下喔...
- 安装的问题?我.net环境怎么装不好???
- 怎么让Button和LinkButton对页面中的校验控件(RequiredFieldValidator等)失效!
- xmlhttp是什么东西。。大家教教我
- Ajax修改视频的播放路径
- 小弟想学习ASP,请问哪里有电子版的好教材下载?
- 帮忙想boiok.net怎么起一个谐音的中文名?
- vs2005出问题啦,不能调试
<ItemTemplate>
应该为:
<asp:TemplateField HeaderText="删除" CommandName="Delete">
<ItemTemplate>
不然你点删除它并不知道要删除
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E1FFC4'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;"); } }
删除提示: <asp:ImageButton ID="delFlowmain" runat="server" CommandName="delete" ImageUrl="~/images/del.gif" CausesValidation="false" OnClientClick="javascript:return confirm('确认删除?')" />