1

我有一个网格视图,其中一个文本框出现在页脚和编辑模板中,用户可以从中更新数据。我在网格的空模板内制作了一个表格,并在其上添加了一个服务器端文本框,以便用户可以在网格中没有记录时将数据插入网格中。网格外有一个服务器端按钮,单击该按钮时,我会保存用户通过网格插入或更新的数据。现在我面临的问题是在保存数据的同时找出网格的空模板中存在的控件。

我的代码如下所示:

<asp:GridView ID="grwBrandInfo" runat="server" Width="100%" HeaderStyle-CssClass="gridheaderstyle"
                                    GridLines="Vertical" AutoGenerateColumns="false" ShowFooter="True" BackColor="White"
                                    OnRowCommand="grwBrandInfo_RowCommand" OnRowEditing="grwBrandInfo_RowEditing"
                                    OnRowDeleting="grwBrandInfo_RowDeleting" OnRowUpdating="grwBrandInfo_RowUpdating"
                                    OnRowDataBound="grwBrandInfo_RowDataBound" OnRowCancelingEdit="grwBrandInfo_RowCancelingEdit"
                                    BorderStyle="None">
                                    <Columns>
                                        <asp:TemplateField HeaderText="Quarts">
                                            <ItemTemplate>
                                                <%#Eval("QUARTS")%>
                                                <asp:HiddenField ID="hdnPERMIT_QUANTITY_ID" runat="server" Value='<%#Eval("PERMIT_QUANTITY_ID") %>' />
                                                <asp:HiddenField ID="hdnQuarts" runat="server" />
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:HiddenField ID="hdnPERMIT_QUANTITY_ID" runat="server" Value='<%#Eval("PERMIT_QUANTITY_ID") %>' />
                                                <asp:TextBox ID="txtFootQuarts" runat="server" CssClass="txtfields" MaxLength="4"></asp:TextBox>
                                            </FooterTemplate>
                                            <EditItemTemplate>
                                                <asp:HiddenField ID="hdnPERMIT_QUANTITY_ID" runat="server" Value='<%#Eval("PERMIT_QUANTITY_ID") %>' />
                                                <asp:TextBox ID="txtEditQuarts" runat="server" EnableViewState="false" Text='<%#Eval("QUARTS")%>'
                                                    CssClass="txtfields" MaxLength="4"></asp:TextBox>
                                            </EditItemTemplate>
                                            <HeaderStyle HorizontalAlign="Center" />
                                            <ItemStyle HorizontalAlign="Center" />
                                            <FooterStyle HorizontalAlign="Center" />
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <FooterTemplate>
                                                <asp:LinkButton ID="lbtnInsert" runat="server" Text="Insert" CssClass="hypfield"
                                                    CommandName="Insert" ValidationGroup="save"></asp:LinkButton>
                                            </FooterTemplate>
                                            <FooterStyle HorizontalAlign="Center" />
                                            <HeaderStyle HorizontalAlign="Center" />
                                        </asp:TemplateField>
                                        <asp:CommandField ShowEditButton="True" HeaderText="Action" ShowDeleteButton="true"
                                            ValidationGroup="save">
                                            <ItemStyle CssClass="hypfield" HorizontalAlign="Center" VerticalAlign="Top" />
                                            <ControlStyle CssClass="hypfield" />
                                            <HeaderStyle HorizontalAlign="Center" />
                                        </asp:CommandField>
                                    </Columns>
                                    <EmptyDataTemplate>
                                        <table border="1" cellpadding="5" cellspacing="0" width="100%">
                                            <tr align="Left" bgcolor="#726E6D">
                                                <td>
                                                    <b>
                                                        <asp:HiddenField ID="hdnPERMIT_QUANTITY_ID" runat="server" Value='0' />
                                                        <asp:Label ID="lblQuarts" runat="server" ForeColor="white" Text="Quarts" CssClass="lblfields"></asp:Label></b>
                                                </td>
                                            </tr>
                                            <tr align="left" id="trEntryNotCompleted" runat="server" bgcolor="#FFFFEE">
                                                <td>
                                                    <asp:TextBox ID="txtQuarts" runat="server" CssClass="txtfields5char" MaxLength="4"></asp:TextBox>
                                                </td>
                                                                                           </tr>
                                        </table>
                                    </EmptyDataTemplate>
                                    <FooterStyle BackColor="#CCCC99" />
                                    <RowStyle BackColor="#F7F7DE" />
                                    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                                    <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                                    <HeaderStyle BackColor="#6B696B" CssClass="gridheaderstyle" Font-Bold="True" ForeColor="White" />
                                    <AlternatingRowStyle BackColor="White" />
                                </asp:GridView> 

   <asp:Button ID="btnSave" runat="server" Text="Save" ValidationGroup="save" OnClick="btnSave_Click" />

所以问题是我在保存数据时如何找到空模板中存在的 txtQuarts 的值

4

1 回答 1

-1

Dim txtId As String = CType(gridHelpDesk.Controls(0).Controls(0).FindControl("txtId"), TextBox).Text

于 2013-09-18T08:27:44.393 回答