本文介绍了gridview的,隐藏的RowDataBound按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常快的问题 - 我不能正确地看到它,但没有任何理由的ASP按钮btnEdit仍可见在GridView?上的RowDataBound(用于测试)我只是想用这个计划将其隐藏后来把if语句周围。

Very quick question - I must not be seeing it properly, but is there any reason why the ASP button "btnEdit" is still visible in the gridview? On RowDatabound (for testing) I'm just trying to hide it with the plan to put an if statement around it later.

code后面(的RowDataBound)

    protected void gvEditUser_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Button btnEdit = (Button)e.Row.FindControl("btnEdit");
        btnEdit.Visible = false;
        if (e.Row.RowState != null)
        {
            if ((e.Row.RowState & DataControlRowState.Edit) > 0)
            {

                CheckBox cbAdmin = (CheckBox)e.Row.FindControl("cbAdmin");
                DataRowView dr = e.Row.DataItem as DataRowView;
                if (Convert.ToBoolean(dr["admin"] = true))
                {
                    cbAdmin.Checked = true;
                }
                else
                {
                    cbAdmin.Checked = false;
                }
            }
        }
    }
}

aspx页面(GridView控件)

        <asp:GridView ID="gvEditUser" runat="server" AllowPaging="True" AutoGenerateColumns="False" OnRowCancelingEdit="gvEditUser_RowCancelingEdit" OnRowEditing="gvEditUser_RowEditing" OnRowCommand="gvEditUser_RowCommand" OnRowDeleting="gvEditUser_RowDeleting" OnPageIndexChanging="gvEditUser_PageIndexChanging" CellPadding="4" GridLines="None" CssClass="size12_text" PageSize="10">
        <Columns>
            <asp:TemplateField HeaderText="Username">
                <ItemTemplate>
                    <asp:Label ID="lbUsername" runat="server" Text='<%# Eval("username") %>' ></asp:Label>
                    <asp:Label ID="lbUserID" runat="server" Text='<%# Eval("userid") %>' Visible="false"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Full Name">
                <ItemTemplate>
                    <asp:Label ID="lbFullName" runat="server" Text='<%# Eval("fullname") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Email">
                <ItemTemplate>
                    <a href="mailto:<%# Eval("email") %>">Email</a>
                    <asp:Label ID="lbEmail" runat="server" Visible="false" Text='<%# Eval("email") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Address">
                <ItemTemplate>
                    <asp:Label ID="lbAddress" runat="server" Text='<%# Eval("housenumber")!=DBNull.Value ? Eval("housetype").ToString() == "0" ? Eval("HouseNumber").ToString() + " " + Eval("Address01").ToString() + " " + Eval("Address02").ToString() + " " + Eval("StreetType").ToString() + "<br />" + Eval("Suburb").ToString() + ", " + Eval("State").ToString() + " " + Eval("Postcode").ToString() + "<br />" + Eval("Country").ToString() : Eval("Address01").ToString() + " " + Eval("HouseNumber").ToString() + " " + Eval("Address02").ToString() + " " + Eval("StreetType").ToString() + "<br />" + Eval("Suburb").ToString() + ", " + Eval("State").ToString() + " " + Eval("Postcode").ToString() + "<br />" + Eval("Country").ToString() : "<div class=\"size11_text\">No Address in system.</div>"%>'></asp:Label>
                    <asp:Label ID="lbAddressRaw" runat="server" Text='<%# Eval("housenumber")!=DBNull.Value ? Eval("housetype").ToString() == "0" ? Eval("HouseNumber").ToString() + " " + Eval("Address01").ToString() + " " + (Eval("Address02")!=DBNull.Value ? Eval("Address02").ToString() + " " : "") + Eval("StreetType").ToString() : Eval("Address01").ToString() + " " + Eval("HouseNumber").ToString() + " " + Eval("Address02").ToString() + " " + Eval("StreetType").ToString() : ""%>' Visible="false"></asp:Label>
                    <asp:Label ID="lbHouseType" runat="server" Text='<%# Eval("housetype") %>' Visible="false"></asp:Label>
                    <asp:Label ID="lbHouseNumber" runat="server" Text='<%# Eval("housenumber") %>' Visible="false"></asp:Label>
                    <asp:Label ID="lbAddress01" runat="server" Text='<%# Eval("address01") %>' Visible="false"></asp:Label>
                    <asp:Label ID="lbAddress02" runat="server" Text='<%# Eval("address02") %>' Visible="false"></asp:Label>
                    <asp:Label ID="lbStreetType" runat="server" Text='<%# Eval("streettype") %>' Visible="false"></asp:Label>
                    <asp:Label ID="lbSuburb" runat="server" Text='<%# Eval("suburb") %>' Visible="false"></asp:Label>
                    <asp:Label ID="lbState" runat="server" Text='<%# Eval("state") %>' Visible="false"></asp:Label>
                    <asp:Label ID="lbPostcode" runat="server" Text='<%# Eval("postcode") %>' Visible="false"></asp:Label>
                    <asp:Label ID="lbCountry" runat="server" Text='<%# Eval("country") %>' Visible="false"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Home Phone">
                <ItemTemplate>
                    <asp:Label ID="lbTelephone" runat="server" Text='<%# Eval("telephone") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Work Phone">
                <ItemTemplate>
                    <asp:Label ID="lbWorkPhone" runat="server" Text='<%# Eval("workphone") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Mobile">
                <ItemTemplate>
                    <asp:Label ID="lbMobile" runat="server" Text='<%# Eval("mobile") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Shirt Size">
                <ItemTemplate>
                    <asp:Label ID="lbShirtSize" runat="server" Text='<%# Eval("shirtsize") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Pant Size">
                <ItemTemplate>
                    <asp:Label ID="lbPantSize" runat="server" Text='<%# Eval("pantsize") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Admin">
                <ItemTemplate>
                    <asp:CheckBox ID="cbAdmin" runat="server" Checked='<%# Convert.ToBoolean(Eval("admin")) %>' Enabled="false" />
                    <asp:Label ID="lbAdmin" runat="server" Text='<%# Eval("admin") %>' Visible="false" ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Last Login">
                <ItemTemplate>
                    <asp:Label ID="lbLastLogin" runat="server" Text='<%# Eval("lastlogin") %>' CssClass="size11_text_blurb"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderStyle-Width="100px">
                <ItemTemplate>
                    <asp:Button ID="btnPasswordReset" runat="server" CssClass="txtbuttonsmall" CommandName="ResetPassword" Text="Reset Password" OnClientClick='<%# Eval("username","return confirm(\"Reset password for {0}?\");") %>'></asp:Button><br />
                    <asp:Button ID="btnEdit" runat="server" CssClass="txtbuttonsmall" CommandName="Edit" Text="Edit User"></asp:Button><br />
                    <asp:Button ID="btnDelete" runat="server" CssClass="txtbuttonsmall" CommandName="Delete" Text="Delete User" OnClientClick='<%# Eval("username","return confirm(\"Delete user {0}?\");") %>'></asp:Button>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:Button ID="btnCancel" runat="server" CommandName="Cancel" Text="Cancel Edit" CssClass="txtbutton"></asp:Button>
                </EditItemTemplate>
            </asp:TemplateField>
        </Columns>
        <AlternatingRowStyle BackColor="#d8e6f0" />
        <EditRowStyle BackColor="#a3cbe8" />
        <HeaderStyle BackColor="#032035" ForeColor="White" CssClass="size12_text" />
        <PagerStyle BackColor="#032035" ForeColor="White" HorizontalAlign="Center" CssClass="size12_text" />
        <RowStyle BackColor="#f9fbfc" />
    </asp:GridView>

干杯,

特伦特

推荐答案

我忘了订阅OnRowDataBound在GridView上。没有一个光明的家伙......

I forgot to subscribe OnRowDataBound on the gridview. Not a bright fella....

这篇关于gridview的,隐藏的RowDataBound按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 03:11