在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 + "\"吗?')");
                   
                }
            }
        }

解决方案 »

  1.   

    <asp:TemplateField HeaderText="删除"> 
                        <ItemTemplate> 
    应该为:
    <asp:TemplateField HeaderText="删除" CommandName="Delete"> 
                        <ItemTemplate> 
    不然你点删除它并不知道要删除
      

  2.   

    protected void  flow_mainGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            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;");        }    }
      

  3.   


    删除提示: <asp:ImageButton ID="delFlowmain" runat="server" CommandName="delete" ImageUrl="~/images/del.gif" CausesValidation="false"  OnClientClick="javascript:return confirm('确认删除?')"  />