在Gridview

时间:2017-02-27 03:51:54

标签: asp.net vb.net gridview

我正在更新这个问题,希望得到一些帮助,因为我被这个问题腌制了。

此代码允许用户填写由三个文本框组成的当前行。

然后,如果需要,用户单击“添加更多行”按钮以添加更多行并填充行。

这没问题。

我的问题是如何显示这些行的结果。

例如,行的布局如下:

Name: John Doe      Address: 123 Address way      Email: Johndoe@yahoo.com
Name: Jane Doe      Address: 1 Druid Hills Rd     Email: Janedoe@otmail.com

当用户点击“继续”时,我想在单独的页面上显示这些结果。

到目前为止,只有最后一条记录,有时会显示第一条记录,但不会显示所有输入的行。

有任何想法如何解决这个问题?

首先,这是我的gridview,然后是我尝试显示结果。

  <asp:gridview ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false" OnRowDeleting="Gridview1_RowDeleting">
    <Columns>
    <asp:BoundField DataField="RowNumber" Visible="false" HeaderText="Row Number" />
    <asp:TemplateField HeaderText="Name">
        <ItemTemplate>
            <asp:TextBox ID="txtname" runat="server" style="width:200px;"></asp:TextBox>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Adress">
        <ItemTemplate>
            <asp:TextBox ID="txtAddress" runat="server" style="width:200px;"></asp:TextBox>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Email">
        <ItemTemplate>
             <asp:TextBox ID="txtEmail" runat="server" style="width:200px;"></asp:TextBox>
        </ItemTemplate>
        <FooterStyle HorizontalAlign="Right" />
        <FooterTemplate>
         <asp:Button ID="ButtonAdd" runat="server" Text="Add More Rows" 
                onclick="ButtonAdd_Click" />
        </FooterTemplate>
    </asp:TemplateField>
   <asp:CommandField ShowDeleteButton="True" />
    </Columns>
</asp:gridview>

我尝试显示失败的行。

Private Sub FillSummary()
    SetRowData()


    Dim rowIndex As Integer = 0

    Dim sc As New StringCollection()

    If ViewState("CurrentTable") IsNot Nothing Then


        Dim dtCurrentTable As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)

        If dtCurrentTable.Rows.Count > 0 Then

            For i As Integer = 1 To dtCurrentTable.Rows.Count


                'extract the TextBox values

                Dim box1 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(1).FindControl("txtname"), TextBox)

                Dim box2 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(2).FindControl("txtaddress"), TextBox)

                Dim box3 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(3).FindControl("txtemail"), TextBox)


                lblPreviewName.Text = box1.Text
                lblPrevieweAddress.Text = box2.Text
                lblPreviewEmail.Text = box3.Text
                'get the values from the TextBoxes

                'then add it to the collections with a comma "," as the delimited values

                sc.Add(lblPreviewName.Text + "," + lblPreviewAddress.Text + "," + lblPreviewEmail.Text)

                rowIndex += 1
            Next

            'Call the method for executing inserts

        End If
    End If

End Sub

0 个答案:

没有答案