ASP.net Repeater控件隐藏列

来源:互联网 发布:jsp源码下载 编辑:程序博客网 时间:2024/06/07 04:06
  在前台将Repeater中的Td标签设为服务器控件

实例:

前台:

//jQuery用来隐藏Repeater的表头列

function ViewOnly(){

    $("#thEdit").hide();

      $("#thDelete").hide();

      $("#tdNew").hide();

   }

 

<table width="100%" border="0" cellpadding="0" cellspacing="1" rules="all" class="tablebk"  >

                          <tr class="tablebtbg">

                           <th  scope="col" style="width: 110px;">酒店th>

                           <th  scope="col" style=" width:80px">区域</th>

                           <th  scope="col" style=" width:110px">负责人</th>

                           <th  scope="col" style=" width:60px">查看</th>

                           <th  scope="col" style=" width:60px" id="thEdit">修改</th>

                           <th  scope="col" style="width: 60px" id="thDelete">删除</th>   //TH用Javascript隐藏

                         </tr>

                             <asp:repeater id="RepList" runat="server" OnItemCommand="RepList_ItemCommand" OnItemDataBound="RepList_ItemDataBound">

                   <itemtemplate>

                        <tr align="center" class="bgbaise">

                            <td align="center">

                                <%#HtmlEncode(Eval("GrogshopName"))%>

                            </td>

                            <td align="center">

                                <%#HtmlEncode(Eval("GrogshopArea"))%>

                            </td>

                            <td align="center">

                                <%#HtmlEncode(Eval("Grogshopprincipal"))%>

                            </td>

                         

                           <td align="center">

                                <a href="../FrontCase/GrogshopInfo_Update.aspx<%#GetEncryptUrlQueryString(Container.DataItem,"View") %>">查看</a>

                            </td>

                            <td align="center" runat="server" id="tdEdit">  //设为服务器控件后台操作

                                <a href="../FrontCase/aa.aspx<%#GetEncryptUrlQueryString(Container.DataItem,"Edit") %>">修改</a>

                            </td>

                            <td align="center" runat="server" id="tdDelete"> //设为服务器控件后台操作

                                <asp:LinkButton ID="lbtnDel" CommandArgument='<%#HtmlEncode(Eval("GrsID")) %>' CommandName="Del" runat="server"><span onclick="return confirm('是否删除记录?');">删除</span></asp:LinkButton>

                            </td>

                        </tr>

                        </itemtemplate>

              </asp:repeater>

                       </table>

 

后台:

//调用前台的Javascript函数

this.ClientJavaScript("ViewOnly();");

 

protected void RepList_ItemDataBound(object sender, RepeaterItemEventArgs e)

        {

            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)

            {

            

                    //,Common.SystemRole.Receive

                    HtmlTableCell tdEdit = e.Item.FindControl("tdEdit") as HtmlTableCell;

                    HtmlTableCell tdDelete = e.Item.FindControl("tdDelete") as HtmlTableCell;

                    tdEdit.Visible = false;

                    tdDelete.Visible = false;

 

                //隐藏编辑、删除列

            }

        }

http://sunhongwei2002.blog.163.com/blog/static/1490070122010112975917403/