zoukankan      html  css  js  c++  java
  • 在GridView隐藏字段

    在GridView中隐藏一字段,方便这条记录的处理,同时隐藏一个Button实现点击这条记录时的处理

    1.绑定

    <asp:TemplateField>
                            <HeaderTemplate>
                                  <label id="forApprove">是否批准</label>  
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:DropDownList ID="approve" runat="server" AutoPostBack="True" OnSelectedIndexChanged="approve_SelectedIndexChanged">
                                <asp:ListItem Selected="True">待定</asp:ListItem>
                                <asp:ListItem>同意</asp:ListItem>
                                <asp:ListItem>不同意</asp:ListItem>
                            </asp:DropDownList>
                             <asp:Label ID="extraID" Visible="false"  runat="server" Text='<%# Eval("ExtraID") %>'></asp:Label>

                            <asp:Button ID="hiddenPost" CommandName="hiddenCommand"  runat="server"
                                Text="hiddenButton" style="display:none" />
                        </ItemTemplate>     
     </asp:TemplateField>

    2.处理

        实现光棒效果,并注册这条记录点击时的处理

       protected void Gv_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                Button btn = e.Row.FindControl("hiddenPost") as Button;
                if (btn != null)
                {
                    e.Row.Attributes["onclick"] = string.Format("javascript:document.getElementById('{0}').click();", btn.ClientID);
                }
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#FED8E0'");
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#99CCFF'");
                }
            }

      
            protected void Gv_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                switch (e.CommandName)
                {
                    case "hiddenCommand":
                        Control cmdControl = e.CommandSource as Control;
                        GridViewRow row = cmdControl.NamingContainer as GridViewRow;
                        string Id = (row.FindControl("extraID") as Label).Text.Trim();
                        if (!string.IsNullOrEmpty(Id))
                        {
                            Response.Redirect("....aspx?extraId=" + Id);
                        }
                        break;
                }
            }

  • 相关阅读:
    atitit.为什么技术的选择方法java超过.net有前途
    HDU 4022 Bombing STL 模拟题
    定制XP引导屏幕背景图像和替换windows这句话
    《STL源代码分析》---stl_heap.h读书笔记
    2015在大型多人在线游戏市场报告
    于Unity3D调用安卓AlertDialog
    jQuery整理笔记5----jQuery大事
    推断字符串数组里面是空的
    软测试-数据结构
    2014第18周三
  • 原文地址:https://www.cnblogs.com/aswater-yuanye/p/3494675.html
Copyright © 2011-2022 走看看