开发者

Why is GridView EditItemTemplate not showing on first click?

开发者 https://www.devze.com 2022-12-15 08:28 出处:网络
I have a GridView with an EditItemTemplate, to which I am binding a Dictionary <as开发者_运维问答p:GridView runat=\"server\" ID=\"VariableList\" ShowHeader=\"false\" AutoGenerateColumns=\"false\"

I have a GridView with an EditItemTemplate, to which I am binding a Dictionary

<as开发者_运维问答p:GridView runat="server" ID="VariableList" ShowHeader="false" AutoGenerateColumns="false" OnRowEditing="VariableList_RowEditing">
    <Columns>                        
        <asp:BoundField ReadOnly="true" DataField="Key" />
        <asp:TemplateField ItemStyle-Width="300">
            <ItemTemplate>
                <asp:Label runat="server" id="VName" Text='<%# Eval("Value") %>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox runat="server" id="VValue" Text='<%# Eval("Value") %>'></asp:TextBox>
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:CommandField ShowEditButton="true" />
    </Columns>
</asp:GridView>

When I click on the Edit button, the RowEditing event is fired (verified with debugger) in which I set the GridViews EditIndex:

protected void VariableList_RowEditing(object sender, GridViewEditEventArgs e)
{
    GridView grid = sender as GridView;

    if (grid == null)
    {
        return;
    }

    grid.EditIndex = e.NewEditIndex;
}

If I set a breakpoint on the grid.EditIndex = e.NewEditIndex; line, it is setting the value to 0 which is the first item which is correct.

However, the asp:TextBox is not displaying. It is showing what is in the ItemTemplate and not in the EditItemTemplate.

However, if I click on Edit button again, it then displays the TextBox.

Any ideas how to get it with the first click?


grid.EditIndex = e.NewEditIndex;
grid.DataBind();
0

精彩评论

暂无评论...
验证码 换一张
取 消