473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Gridview - add/remove rows on the fly, no database

1
I have a gridview that has a blank row with 2 input fields: file to upload, and a description of the file. They click Add and a new row is added, Remove and the row is removed.

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
  1. <asp:GridView ID="gFiles" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Visible="False">
  2.              <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
  3.              <Columns>
  4.                 <asp:TemplateField HeaderText="File to upload">
  5.                      <ItemTemplate>
  6.                          <asp:FileUpload ID="FileToUpload" runat="server" Width="400px" />
  7.                      </ItemTemplate>
  8.                  </asp:TemplateField>
  9.                  <asp:TemplateField HeaderText="Description">
  10.                      <ItemTemplate>
  11.                          <asp:TextBox ID="tbDesc" runat="server" Height="24px"
  12.                              MaxLength="200" TextMode="MultiLine" Width="300px"></asp:TextBox>
  13.                      </ItemTemplate>
  14.                  </asp:TemplateField>
  15.                  <asp:TemplateField ShowHeader="False" HeaderText="Add">
  16.                      <ItemTemplate>
  17.                          <asp:LinkButton ID="btnAdd" runat="server" CausesValidation="false" CommandName="Add"
  18.                              Text="Add"></asp:LinkButton>
  19.                      </ItemTemplate>
  20.                  </asp:TemplateField>
  21.                               </Columns>
  22. <Columns>
  23.             <asp:CommandField ShowDeleteButton="True" DeleteText="Remove" /></Columns> 
  24.              <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
  25.              <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
  26.          </asp:GridView>
  27.  
Here's the code behind:
Expand|Select|Wrap|Line Numbers
  1.        If dtFiles.Rows.Count = 0 Then
  2.             'crate the blank table
  3.             dtFiles.Columns.Add("FileToUpload", GetType(FileUpload))
  4.             dtFiles.Columns.Add("tbDesc", GetType(TextBox))
  5.             dtFiles.Columns.Add("Add", GetType(LinkButton))
  6.         End If
  7.         'Convert datagrid to dtFiles
  8.         Dim gr As GridViewRow
  9.         Dim nr As DataRow
  10.         For Each gr In gFiles.Rows
  11.             nr = dtFiles.NewRow
  12.             Dim tb As New TextBox
  13.             tb = CType(gr.FindControl("tbDesc"), TextBox)
  14.             nr(1) = tb
  15.             dtFiles.Rows.Add(nr)
  16.         Next
  17.  
  18.         If e.CommandName = "Add" Then
  19.             'Add new row to dtFiles
  20.             nr = dtFiles.NewRow
  21.             dtFiles.Rows.Add(nr)
  22.         ElseIf e.CommandName = "Remove" Then
  23.             dtFiles.Rows.RemoveAt(gFiles.SelectedIndex)
  24.             gFiles.DataSource = dtFiles
  25.             gFiles.DataBind()
  26.         End If
  27.         gFiles.DataSource = dtFiles
  28.         gFiles.DataBind()
Feb 19 '08 #1
1 7274
debasisdas
8,127 Expert 4TB
Question moved to .net forum.
Feb 20 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John_H | last post by:
Re: ASP.NET 2.0 I would like suggestions or code examples on how to collect a variable length list of input data (item# & item quantity specifically). I thought that I could accomplish this...
0
by: googleThis | last post by:
I have a GridView control on a ASP.NET 2.0 page. I load the GridView with a SqlDataReader that gets its data from a stored procedure. Here is how the grid is defined: <asp:GridView...
4
by: Tomasz Jastrzebski | last post by:
Hello Everyone, I have a GridView control bound to a plain DataTable object. AutoGenerateEditButton is set to true, Edit button gets displayed, and RowEditing event fires as expected.
2
by: Greg | last post by:
I have a gridview on my form which I have populated using a datareader. What I would like to do is to be able to remove specified records from the gridview, without affecting the source of the...
7
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi all! I have a gridview inside a datagrid (nested) for which (gridview) the rowcommand is not raised in order to delete a row from the grid! I also tried OnRowCommand="method", didn't work...
0
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
0
by: ganesh22 | last post by:
Hi... Iam using GridView in asp.net(2.0) .My requirement is user can add,update,delete in gridview I written the code for add & update but can u help adding rows in grid view My code: ...
1
Frinavale
by: Frinavale | last post by:
I'm working on an ASP.NET application using VB.NET for server side code. I have a GridView listing a bunch of stuff. Above the GridView I have a checkbox named "ChkBx_SelectAll". If this...
3
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
I have a gridview that uses a sqldatasource. The rows of the gridview are editable. When the gridview is in edit mode, one of the columns is a dropdown. In testing the editing, I deleted the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.