简体   繁体   中英

VB.net Datagrid Set EditItemTemplate Field Visible

I have a datagrid like below

<asp:datagrid id="grid1" OnEditCommand="Grid_Edit" AutoGenerateColumns="False">
    <Columns>
        <asp:TemplateColumn HeaderText="No" HeaderStyle-HorizontalAlign="Center"> 
            <EditItemTemplate><asp:TextBox ID="txtNo" runat="server" Text="some text"></asp:TextBox></EditItemTemplate> 
            <ItemTemplate><asp:Label ID="lblNo" runat="server" Text="No"></asp:Label></ItemTemplate> 
        </asp:TemplateColumn> 
        <asp:TemplateColumn HeaderText=""> 
            <EditItemTemplate>
                <asp:LinkButton ID="lbkEditUpdate" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton> 
                <asp:LinkButton ID="lnkEditCancel" runat="server" CausesValidation="True" CommandName="Cancel" Text="Cancel"></asp:LinkButton> 
            </EditItemTemplate> 
            <ItemTemplate><asp:LinkButton ID="lblEdit" runat="server" Text="Edit" CommandName="Edit"></asp:LinkButton></ItemTemplate> 
        </asp:TemplateColumn> 
    <Columns>
</asp:datagrid>

Is there any way for me to control the EditItemTemplate where "txtNo" visible = false after I clicked the edit button? I have tried many approaches and no luck for me :-(

I have something like below but of course it doesn't work at all.

Sub Grid_Edit(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles Grid.EditCommand
    CType(grid1.Controls(0).Controls(e.Item.ItemIndex).FindControl("txtNo"), TextBox).Visible = False
End Sub

Is there anyway to do this?? I have stuck for day to figure it out, and your gentle help will be appreciated very much :-)
(P/S: I need to keep the column visible)

Answer found here and here

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM