非常に簡単な質問-正しく表示されていないはずですが、ASPボタン「btnEdit」がまだグリッドビューに表示されている理由はありますか?RowDatabound(テスト用)では、後でifステートメントを配置する計画で非表示にしようとしています。
コードビハインド(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>
乾杯、
トレント