Gridview编辑无法正常工作

时间:2013-08-16 10:49:43

标签: asp.net .net vb.net visual-studio-2008

我有以下gridview:

<asp:GridView ID="GrdAll" runat="server" AutoGenerateColumns="false" ShowHeader="false"
        Width="40%" GridLines="None" CellPadding="2" CellSpacing="2">
        <AlternatingRowStyle CssClass="AltColor22" />
        <RowStyle CssClass="AltColor21" />
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <table width="100%" class="TableBorder">
                        <tr>
                            <td valign="top" align="left">
                                <asp:Label ID="lblName" runat="server" />
                                <hr />
                            </td>
                        </tr>
                        <tr>
                            <td valign="top" align="left" class="TableBorder">
                                <asp:GridView ID="GrdContent" runat="server" AutoGenerateColumns="False"
                                    Width="100%" GridLines="None" CellPadding="2" CellSpacing="2" 
                                    OnRowDataBound="GrdContent_RowDataBound" OnRowEditing="GrdContent_RowEditing"><%----%>
                                    <Columns>
                                        <asp:TemplateField HeaderText="Kiosk ID" HeaderStyle-HorizontalAlign="Left">
                                            <ItemTemplate>
                                                <asp:Label ID="lblKiosID" runat="server"></asp:Label>
                                            </ItemTemplate>
                                              <EditItemTemplate>
                                                <asp:TextBox ID="txtKiosk" runat="server" Text ='<%#Eval("HBEmailID") %>'></asp:TextBox>
                                            </EditItemTemplate>
                                            <HeaderStyle HorizontalAlign="Left" />
                                        </asp:TemplateField>

                                        <asp:TemplateField HeaderText="Email ID" HeaderStyle-HorizontalAlign="Left">
                                         <HeaderStyle HorizontalAlign="Left" />
                                            <ItemTemplate>
                                                <asp:Label ID="lblEmail" runat="server"></asp:Label>
                                            </ItemTemplate>

                                            <EditItemTemplate>
                                                <asp:TextBox ID="txtEmail" runat="server" Text ='<%#Eval("HBEmailID") %>'></asp:TextBox>
                                            </EditItemTemplate>

                                        </asp:TemplateField>
                                        <asp:TemplateField ShowHeader="False">
                                            <ItemTemplate>
                                                <asp:LinkButton ID="LinkButton1" runat="server"  CommandName="Edit"
                                                    Text="Edit" ></asp:LinkButton>
                                            </ItemTemplate>
                                            <EditItemTemplate>
                                                <asp:LinkButton ID="LinkButton3" runat="server"  CommandName="Update"
                                                    Text="Update"></asp:LinkButton>
                                                &nbsp;<asp:LinkButton ID="LinkButton2" runat="server"  CommandName="Cancel"
                                                    Text="Cancel"></asp:LinkButton>
                                            </EditItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

在此,编辑功能无效。

点击编辑按钮,它没有显示任何内容。 (它应该显示我要编辑的文本框)

以下是代码:

Protected Sub GrdContent_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)

    Dim row As GridViewRow = DirectCast(TryCast(sender, Control).Parent.Parent, GridViewRow)
    Dim index As Integer = row.RowIndex

    CType(row.FindControl("GrdContent"), GridView).EditIndex = e.NewEditIndex
    DBName = CType(row.FindControl("lblName"), Label).Text
    bindContentGrid(CType(row.FindControl("GrdContent"), GridView), DBName)
End Sub

请帮帮我,它不会给我错误,但它也没有显示我要编辑的文本框。

1 个答案:

答案 0 :(得分:2)

问题可能出现在以下代码

bindContentGrid(CType(row.FindControl("GrdContent"), GridView), DBName)

如果该代码未返回任何记录,则不会显示任何内容。确保它返回一些行。