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;
                }
            }

  • 相关阅读:
    HDU 2196 Computer
    HDU 1520 Anniversary party
    POJ 1217 FOUR QUARTERS
    POJ 2184 Cow Exhibition
    HDU 2639 Bone Collector II
    POJ 3181 Dollar Dayz
    POJ 1787 Charlie's Change
    POJ 2063 Investment
    HDU 1114 Piggy-Bank
    Lca hdu 2874 Connections between cities
  • 原文地址:https://www.cnblogs.com/aswater-yuanye/p/3494675.html
Copyright © 2011-2022 走看看