473,837 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to add a row to the table web control dynamically in asp .net 2.0 on a button click retaining the user input in previous rows?

Hi All,

I am very new to .net and trying to develop a small application.
I am using asp .net 2.0.

I have a table control (server) in my code that has header row like

<asp:Table id="Table1"
GridLines="Both "
HorizontalAlign ="Center"
Runat="server" Height="1px" Width="523px"
BackColor="Pale Turquoise"
BorderStyle="Gr oove">
<asp:TableRow runat="server" Height="21px">
<asp:TableCel l runat="server" Width="105px">C ell
<asp:TableCel l runat="server" Width="515px">C ell
<asp:TableCel l runat="server" Width="232px">C ell

On page load event, I call "addRow" routine that adds a row to the
above table.
This row has totally 3 table cells in it, out of which the first 2
table cells contain "text box" in them and the last table cell contain
a "checkbox" in it.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
If Not Page.IsPostBack Then
End If
End Sub

Sub addRow()
Dim numrows As Integer = 1
Dim numcells As Integer = 3
Dim j As Integer = Table1.Rows.Cou nt + 1

Dim r As New TableRow()
Dim i As Integer
For i = 0 To numcells - 1
Dim c As New TableCell()
If i = 0 Or i = 1 Then
Dim txtBx As New TextBox()
txtBx.ID = "txtBx" & j & i
c.Controls.Add( txtBx)
Dim chkBx As New CheckBox()
chkBx.ID = "chkBx" & j & i
c.Controls.Add( chkBx)
End If
Next i
Table1.Rows.Add (r)
End Sub

Now, I have 2 buttons (web) on my page.
1) => "btnAdd" --> allows user to add more rows to the table.
2) => "btnDone" --> should display all the values that user has entered
in all the textboxes and checkboxes of the table "table1".

I have the following code

Protected Sub btnAdd_Click(By Val sender As Object, ByVal e As
System.EventArg s) Handles btnAdd.Click
Call addRow()
End Sub
Protected Sub btnDone_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles btnDone.Click

Dim m As Integer
Dim n As Integer
Dim cell1val As String = ""
Dim cell2val As String = ""
Dim cell3val As Boolean

For m = 1 To Table1.Rows.Cou nt - 1
For n = 0 To 2
Select Case n
Case 0
Dim strID As String = "txtBx" & m & n
cell1val =
CType(Table1.Ro ws(m).Cells(n). FindControl(str ID), TextBox).Text
Case 1
Dim strID As String = "txtBx" & m & n
cell2val =
CType(Table1.Ro ws(m).Cells(n). FindControl(str ID), TextBox).Text
Case 2
Dim strID As String = "chkBx" & m & n
cell3val =
CType(Table1.Ro ws(m).Cells(n). FindControl(str ID), CheckBox).Check ed
End Select
response.write = cel1val & "<BR>" & "<BR>" & cell2val &
"<BR>" & cell3val
End Sub

My probelms here are:

1) when I click on "btnAdd"... ..it does not add any new row to the
table. My table seems to have 1 row always. Clicking on the "btnAdd"
does not increment the "table rows".

2) Since I failed to add more rows to the table, I tried to display
the values from the table by clicking "btnDone". After entering the
values to both the text boxes and check box...when I click on
"btnDone".. ..my table row (with text box, check box) disappears and
table reamins with the header row.
I want to retain the table with all the values that have been entered.

Can you guys let me know what I am missing?
Any help in this regard is greatly appreciated.


May 19 '06 #1
0 2099

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Thanks | last post by:
I have a routine that is called on Page_Init. It retrieves folder records from a database which I display as Link Buttons in a table cell. I set the table cell's bgcolor to a default color (say black for example). I am dynamically creating the LinkButton controls and adding them into the table cell and I've also hooked up an event handler for each LinkButton's Click event. This all works fine. Now in the Link Button's Click event...
by: Bijoy Naick | last post by:
I have something strange going on.. My .aspx page contains a file upload control, a "Import Data" button, a "newTransactions" <asp:table>, a"SaveTrans" button and an confMsg label. First the user selects a file, then clicks Import Data. The page now reads the PostedFile and displays each line as a new row in the newTransactions table. All of this works fine. For now, I've programmed SaveTrans_Click to display the number of rows in the...
by: Al Wilkerson | last post by:
Hey, I have a Web Form with a drop down list, textbox, and search button. When click the search button an SQL server database is queried fordata. Once I have the data in a dataset I use the dataset to dynamically create a Html Table control. I want to display the table on another frame page (target="main") without the web form controls (i.e. the textbox, search button, and dropdown list). I just want the table displayed only on the...
by: Al Wilkerson | last post by:
Hey, I have a Web Form with a drop down list, textbox, and search button. When click the search button an SQL server database is queried fordata. Once I have the data in a dataset I use the dataset to dynamically create a Html Table control. I want to display the table on another frame page (target="main") without the web form controls (i.e. the textbox, search button, and dropdown list). I just want the table displayed only on the...
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update button will verify the information that has been entered and updates the data base if the data is correct. Update will throw an exception if the data is not validate based on some given rules. I also have a custom error handling page to show the...
by: JonH | last post by:
Ok, I have this dynamically created table in my one of my php forms that shows the names of the people the user has entered into a text field. When they hit add a row displays, showing the name they entered. Also, an image that allows them to delete shows beside the name upon creation. The delete removes the name from the table and pushes the other names to the top. Simple stuff, however, if I delete the last name displayed(the bottom of...
by: bharathmngl | last post by:
now iam trying to add rows dynamically into the table when i click "ADD ROW" button. It should also have the option to delete the selected row. So Please help me to find code.... And also please tell me how to add textarea and radiobutton in to the dynamically created rows.. Here is my code; <html> <head> <title>Untitled Document</title>
by: Allen Chen [MSFT] | last post by:
Hi Richard, Quote from Richard================================================== However I also want to be able to remove the panes. I have tried to include this, but find that when I first add the pane the remove event does not get handled, though thereafter it is handled without problems. ==================================================
by: azegurb | last post by:
Hello, I have one question again i created one table again and in this table i added some another options for ex at the previous table there were only one problem sum of the dynamically added rows in this beside sum i need to sum of the tax for ex: in column1 i added 300 and into 2-nd column i Chose 10% i would like when i chose from drop down box 10% Let in the 2-nd column appear 10% of the value which i addee first column for ex...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.