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

  • 相关阅读:
    期末考试冬眠
    题解 P1457 【城堡 The Castle】
    题解 P1052 【过河】
    题解 P5663 【加工零件【民间数据】】
    与 macOS 10.12 兼容的OpenCV版本
    summarise() regrouping output 警告
    binary_crossentropy和BinaryCrossentropy的区别
    损失函数BinaryCrossentropy例子说明
    理解功能强大的sed替换命令
    理解GAN对抗神经网络的损失函数和训练过程
  • 原文地址:https://www.cnblogs.com/aswater-yuanye/p/3494675.html
Copyright © 2020-2023  润新知