码迷,mamicode.com
首页 > 其他好文 > 详细

GridView CommandArgument 绑定多个参数

时间:2014-11-13 16:24:36      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:style   io   color   ar   os   使用   sp   for   div   

我们在使用GridView的时候 有时会需要绑定多个参数

  1.             <asp:GridView ID="gvwVoxListAll" runat="server" Width="100%" AutoGenerateColumns="False" 
  2.                           AllowPaging="True" OnPageIndexChanging="gvwVoxListAll_PageIndexChanging" ShowCheckBoxColumn="True" HasGridValue="False" NewSortExpression="" OnRowCommand="gvwVoxListAll_RowCommand" BorderColor="#F8D791" CssClass="tableCssBga1">
  3.                 <Columns>
  4.                 <asp:BoundField DataField="group_placard_id" HeaderText="编号" >
  5.                 <HeaderStyle CssClass="header_myinform" />
  6.                     <ItemStyle CssClass="header_myinform" HorizontalAlign="Center" VerticalAlign="Middle" />
  7.                     <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
  8.                 </asp:BoundField>
  9.                 <asp:BoundField DataField="group_placard_title" HeaderText="公告标题" >
  10.                 <HeaderStyle CssClass="header_myinform" />
  11.                     <ItemStyle CssClass="header_myinform" HorizontalAlign="Center" VerticalAlign="Middle" />
  12.                     <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
  13.                 </asp:BoundField>
  14.                 <asp:BoundField DataField="group_name" HeaderText="群组名称" >
  15.                 <HeaderStyle CssClass="header_myinform" />
  16.                     <ItemStyle CssClass="header_myinform" HorizontalAlign="Center" VerticalAlign="Middle" />
  17.                     <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
  18.                 </asp:BoundField>
  19.                 <asp:BoundField DataField="group_placard_time" HeaderText="发布时间" >
  20.                 <HeaderStyle CssClass="header_myinform" />
  21.                     <ItemStyle CssClass="header_myinform" HorizontalAlign="Center" VerticalAlign="Middle" />
  22.                     <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
  23.                 </asp:BoundField>
  24.                 <asp:TemplateField HeaderText="操作">
  25.                     <ItemTemplate>
  26.                         <asp:LinkButton ID="btEdit" runat="server" CausesValidation="False" CommandName="editData"
  27.                             CssClass="lb" CommandArgument=‘<%# Eval("group_placard_id")+","+Eval("group_id")  %>‘>修改</asp:LinkButton>
  28.                         <asp:LinkButton ID="dtDelete" runat="server" CausesValidation="False" CommandName="delData"
  29.                             CommandArgument=‘<%# Eval("group_placard_id") %>‘ CssClass="lb" OnClientClick=‘if(confirm("您确定删除吗?"))return true;else return false;‘>删除</asp:LinkButton>
  30.                     </ItemTemplate>
  31.                     <ItemStyle Wrap="False" CssClass="main_myinform" />
  32.                     <HeaderStyle Width="20%" CssClass="main_myinform" />
  33.                 </asp:TemplateField>           
  34.                 </Columns>
  35.                 <PagerSettings FirstPageText="第一页" LastPageText="最后页" Mode="NextPreviousFirstLast" NextPageText="下一页" PreviousPageText="上一页" Visible="False" />
  36.                 <PagerStyle HorizontalAlign="Right" />
  37.                 <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" BackColor="#FFF7E5" CssClass="trCssBga1" />
  38.             </asp:GridView>

        后置代码:

  1.     protected void gvwVoxListAll_RowCommand(object sender, GridViewCommandEventArgs e)
  2.     {
  3.         if (e.CommandName.Equals("editData"))
  4.         {
  5.             string[] estr = e.CommandArgument.ToString().Split(‘,‘);
  6.             string placardID = Convert.ToString(estr[0]);
  7.             string groupID = Convert.ToString(estr[1]);
  8.             Response.Redirect("addPlacard.aspx?mark=edit&placardID=" + placardID + "&groupID=" + groupID);
  9.         }
  10.         if (e.CommandName.Equals("delData"))
  11.         {
  12.             string placardID = e.CommandArgument.ToString();
  13.             int result = placard.DelPlacard(placardID);
  14.             if (result > 0)
  15.             {
  16.                 this.bindData();
  17.                 new BaseTool().showAlert("删除成功!");
  18.             }                
  19.             else
  20.                 new BaseTool().showAlert("删除失败!");
  21.         }
  22.     }

GridView CommandArgument 绑定多个参数

标签:style   io   color   ar   os   使用   sp   for   div   

原文地址:http://www.cnblogs.com/hjtdlx/p/4095102.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!