GridView的一些操作

GridView删除行

  1. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting">  
  2.     <Columns>   
  3.         <asp:BoundField DataField="id" HeaderText="id" />  
  4.         <asp:BoundField DataField="name" HeaderText="name" />  
  5.         <asp:TemplateField ShowHeader="False">  
  6.             <ItemTemplate>  
  7.                 <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"  
  8.                     Text="删除" OnClientClick='<%#  "if (!confirm(\"你确定要删除" + Eval("name").ToString() + "吗?\")) return false;"%>'></asp:LinkButton>  
  9.             </ItemTemplate>  
  10.         </asp:TemplateField>  
  11.     </Columns>  
  12.  </asp:GridView>  

批量删除

前台

 <asp:TemplateField ItemStyle-Width="8%">
	<HeaderStyle Wrap="False"></HeaderStyle>
				            <ItemStyle></ItemStyle>
				            <HeaderTemplate>
 <asp:CheckBox id="Hk_SelectAll" onclick="javascript:CheckAllGridCheckBox(this,'Hk_Select');"
	 runat="server" Text="全选"></asp:CheckBox>
				            </HeaderTemplate>
				            <ItemTemplate>
				                  <span name="sel" selname="sel">
					            <asp:CheckBox id="Hk_Select" onclick="javascript:CheckOneGridItem('Hk_SelectAll','gv_recommendHouse','Hk_Select');"
						            runat="server" Visible="true"></asp:CheckBox></span>
				            </ItemTemplate>
				          </asp:TemplateField>


protected void btn_Agent_delete_Click(object sender, EventArgs e)
        {
            string ids = "", members = "";

            for (int i = 0; i < gv_recommendAgent.Rows.Count; i++)
            {
                if (((CheckBox)gv_recommendAgent.Rows[i].Cells[0].FindControl("Ak_Select")).Checked == true)
                {
                    ids += gv_recommendAgent.DataKeys[i].Value + ",";
                    members += gv_recommendAgent.DataKeys[i].Value + ",";
                }
            }

            Loan.Function.boc.RecommendData.DelRecommend(GetInterger(user.BankId.ToString(), 1), listType.ToString(), ids);
            Response.Redirect("/Manager/boc/recommendlist.aspx?list=2");
        }

posted @ 2010-10-28 11:17  老皆知  阅读(391)  评论(0编辑  收藏  举报