编辑模板不显示

时间:2013-05-15 06:34:39

标签: asp.net vb.net gridview edititemtemplate

我有一个gridview,它有一个项目模板和一个编辑模板。问题是,每当我单击编辑按钮时,编辑模板都不会显示。

这是我的页面代码:

 <asp:GridView 
            ID="RoutesGridView" 
            runat="server" 
            CssClass="table table-striped table-hover"
            GridLines="None"
            AutoGenerateColumns="False" 
            DataKeyNames="RouteId,LocationId,ConcurrencyId" 
            AllowPaging="true"
            EmptyDataText="No Information Retrieved">
            <Columns>
                <asp:TemplateField Visible="false">
                    <EditItemTemplate>
                        <asp:Label id="RouteIdLB" runat="server" Text='<%# Bind("RouteId") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label id="RouteIdLB" runat="server" Text='<%# Bind("RouteId") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Name" SortExpression="Name">
                    <EditItemTemplate>
                        <asp:TextBox ID="NameTB" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="NameLB" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Description" SortExpression="Description" >
                    <EditItemTemplate>
                        <asp:TextBox ID="DescriptionTB" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="DescriptionLB" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>                   
                <asp:TemplateField HeaderText="Time Zone" SortExpression="TimeZoneCode">
                    <EditItemTemplate>
                        <asp:DropDownList ID="TimeZoneDDL" runat="server" DataSource="<%# GetTimeZones() %>" AppendDataBoundItems="true" DataTextField="TimeZoneCode" DataValueField="TimeZoneId" SelectedValue='<%# Bind("TimeZoneId") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("TimeZoneCode") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Is Active" SortExpression="IsActive" HeaderStyle-CssClass="textCenterAlign" ItemStyle-CssClass="textCenterAlign">
                    <EditItemTemplate>
                        <asp:CheckBox ID="IsActiveCB" runat="server" Checked='<%# Bind("IsActive") %>' />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <%# IIf(Eval("IsActive").Equals(True), "<i class='icon-ok'></i>", " ")%>                 
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Is Deleted" SortExpression="IsDeleted" HeaderStyle-CssClass="textCenterAlign" ItemStyle-CssClass="textCenterAlign">
                    <EditItemTemplate>
                        <asp:CheckBox ID="IsDeletedCB" runat="server" Checked='<%# Bind("IsDeleted") %>' Enabled="False" />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <%# IIf(Eval("IsDeleted").Equals(True), "<i class='icon-ok'></i>", " ")%>                     
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Actions" ItemStyle-CssClass="actions">
                    <EditItemTemplate>
                        <asp:LinkButton ID="SaveButton" runat="server" CssClass="btn btn-mini btn-primary hiddenButton" CommandName="Update" Visible="True" Enabled="True" ToolTip="Save pending changes" CommandArgument='<%# CType(Container, GridViewRow).RowIndex %>'><i class="icon-ok icon-white"></i>Save</asp:LinkButton>
                        <asp:LinkButton ID="CancelButton" runat="server" CssClass="btn btn-mini btn-danger hiddenButton" CommandName="Cancel" Visible="True" Enabled="True" ToolTip="Cancel pending changes" CommandArgument='<%# CType(Container, GridViewRow).RowIndex %>'><i class="icon-ban-circle icon-white"></i>Cancel</asp:LinkButton>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="EditButton" runat="server" CssClass="btn btn-mini btn-primary hiddenButton" CommandName="Edit" Visible="True" Enabled="True" ToolTip="Edit this entry" CommandArgument='<%# CType(Container, GridViewRow).RowIndex %>'><i class="icon-edit icon-white"></i>Edit</asp:LinkButton>
                        <asp:LinkButton ID="DeleteButton" runat="server" CssClass="btn btn-mini btn-danger hiddenButton" CommandName="Delete" Visible="True" Enabled="True" ToolTip="Delete this entry" CommandArgument='<%# CType(Container, GridViewRow).RowIndex %>' OnClientClick='return confirm("Are you certain that you want to delete this entry?");'><i class="icon-trash icon-white"></i>Delete</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

VB代码背后:

 Protected Sub RoutesGridView_RowEditing(ByVal sender As System.Object, ByVal e As GridViewEditEventArgs) Handles RoutesGridView.RowEditing
    Dim gv As GridView = CType(sender, GridView)
    Dim row As GridViewRow = gv.Rows(e.NewEditIndex)
    Dim RouteId As Integer = CInt(CType(row.FindControl("RouteIdLB"), Label).Text)
    _Route = RouteManager.GetItem(RouteId, _dftIdentity)
    gv.EditIndex = e.NewEditIndex
    RoutesGridView_DataBind()
End Sub

Protected Sub RoutesGridView_RowCancelingEdit(ByVal sender As System.Object, ByVal e As GridViewCancelEditEventArgs) Handles RoutesGridView.RowCancelingEdit
    _Route = Nothing
    RoutesGridView.EditIndex = -1
    RoutesGridView_DataBind()
End Sub

Protected Sub RoutesGridView_RowUpdating(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles RoutesGridView.RowUpdating
    Try
        Dim gv As GridView = CType(sender, GridView)
        Dim row As GridViewRow = gv.Rows(e.RowIndex)
        With _Route
            .Name = CType(row.FindControl("NameTB"), TextBox).Text
            .TimeZoneId = CType(row.FindControl("TimeZoneDDL"), DropDownList).SelectedValue
            .IsActive = CType(row.FindControl("IsActiveCB"), CheckBox).Checked
        End With
        RouteManager.Update(_Route, _dftIdentity)
        _Route = Nothing
        gv.EditIndex = -1
        RoutesGridView_DataBind()
    Catch ex As Exception
        ProcessException(ex)
    End Try
End Sub

1 个答案:

答案 0 :(得分:1)

您需要从auto更改网格编辑表单属性 到模板