The problem is:
When a new row is added, I loop through the existing gridview rows, store the data in a dataset, and rebind. In debug mode, I see the values I entered but when I rebind, it's not displayed in the gridview.
Here's the code aspx code:
Expand|Select|Wrap|Line Numbers
- <asp:GridView ID="gFiles" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Visible="False">
- <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
- <Columns>
- <asp:TemplateField HeaderText="File to upload">
- <ItemTemplate>
- <asp:FileUpload ID="FileToUpload" runat="server" Width="400px" />
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="Description">
- <ItemTemplate>
- <asp:TextBox ID="tbDesc" runat="server" Height="24px"
- MaxLength="200" TextMode="MultiLine" Width="300px"></asp:TextBox>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField ShowHeader="False" HeaderText="Add">
- <ItemTemplate>
- <asp:LinkButton ID="btnAdd" runat="server" CausesValidation="false" CommandName="Add"
- Text="Add"></asp:LinkButton>
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- <Columns>
- <asp:CommandField ShowDeleteButton="True" DeleteText="Remove" /></Columns>
- <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
- <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
- </asp:GridView>
Expand|Select|Wrap|Line Numbers
- If dtFiles.Rows.Count = 0 Then
- 'crate the blank table
- dtFiles.Columns.Add("FileToUpload", GetType(FileUpload))
- dtFiles.Columns.Add("tbDesc", GetType(TextBox))
- dtFiles.Columns.Add("Add", GetType(LinkButton))
- End If
- 'Convert datagrid to dtFiles
- Dim gr As GridViewRow
- Dim nr As DataRow
- For Each gr In gFiles.Rows
- nr = dtFiles.NewRow
- Dim tb As New TextBox
- tb = CType(gr.FindControl("tbDesc"), TextBox)
- nr(1) = tb
- dtFiles.Rows.Add(nr)
- Next
- If e.CommandName = "Add" Then
- 'Add new row to dtFiles
- nr = dtFiles.NewRow
- dtFiles.Rows.Add(nr)
- ElseIf e.CommandName = "Remove" Then
- dtFiles.Rows.RemoveAt(gFiles.SelectedIndex)
- gFiles.DataSource = dtFiles
- gFiles.DataBind()
- End If
- gFiles.DataSource = dtFiles
- gFiles.DataBind()