Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Adding rows to html table dynamically

Reply
Thread Tools

Adding rows to html table dynamically

 
 
Valli
Guest
Posts: n/a
 
      09-21-2007
Hi,

I am a fresher to asp.net programming.

I want to add rows to html table dynamically. I am able to do this
using javascript.
But i need to add rows to table in aspx.vb page. The oding what i wrote
adds a row to a table but doesnt display the record.

When I retrieve value from the cell, it returns the value. Is there
anything wroing in my coding.
Please help me friends.

My code follows here:
Private Sub psAddNewRow()

Dim flag As Boolean = False



flag = True

If flag = True Then

Dim row As New HtmlControls.HtmlTableRow

Dim td1 As New HtmlControls.HtmlTableCell

Dim td2 As New HtmlControls.HtmlTableCell

Dim td3 As New HtmlControls.HtmlTableCell

Dim td4 As New HtmlControls.HtmlTableCell

Dim td5 As New HtmlControls.HtmlTableCell

Dim td6 As New HtmlControls.HtmlTableCell

Dim td7 As New HtmlControls.HtmlTableCell

Dim td8 As New HtmlControls.HtmlTableCell

Dim td9 As New HtmlControls.HtmlTableCell

Dim td10 As New HtmlControls.HtmlTableCell

Dim td11 As New HtmlControls.HtmlTableCell

Dim strHtml1 As String

Dim strHtml2 As String

strHtml1 = "<INPUT TYPE=\""Button\"" CLASS=\""but\""
onClick=\""EditRow(this)\"" VALUE=\""Edit\"">"

strHtml2 = "<INPUT TYPE=\""Button\"" CLASS=\""but\""
onClick=\""DeleteRow(this)\"" VALUE=\""Delete\"">"

td1.InnerHtml = "Order"

td2.InnerHtml = "Order2"

td3.InnerHtml = "Order3"

td4.InnerHtml = "Order4"

td5.InnerHtml = "Order5"

td6.InnerHtml = "Order6"

td7.InnerHtml = "Order7"

td8.InnerHtml = "Order8"

td9.InnerHtml = "Order9"

'td10.InnerHtml = strHtml1

'td11.InnerHtml = strHtml2

row.Cells.Add(td1)

row.Cells.Add(td2)

row.Cells.Add(td3)

row.Cells.Add(td4)

row.Cells.Add(td5)

row.Cells.Add(td6)

row.Cells.Add(td7)

row.Cells.Add(td

row.Cells.Add(td9)

'row.Cells.Add(td10)

'row.Cells.Add(td11)

tblorederlist.Rows.Add(row) 'Add a row to table

lblOrderOrPosition.Text = tblorederlist.Rows.Count
--
Thanks & Regards
Valli


 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2hhaHphZCBBaG1lZA==?=
Guest
Posts: n/a
 
      09-21-2007
Here is the code to solve your problem

TableRow tr = new TableRow();
TableCell tc1 = new TableCell();
TableCell tc2 = new TableCell();
tc1.Text = "tc1";
tc2.Text = "tc2";
tr.Cells.Add(tc1);
tr.Cells.Add(tc2);
this.Table1.Rows.Add(tr);

Regards
Shahzad

"Valli" wrote:

> Hi,
>
> I am a fresher to asp.net programming.
>
> I want to add rows to html table dynamically. I am able to do this
> using javascript.
> But i need to add rows to table in aspx.vb page. The oding what i wrote
> adds a row to a table but doesnt display the record.
>
> When I retrieve value from the cell, it returns the value. Is there
> anything wroing in my coding.
> Please help me friends.
>
> My code follows here:
> Private Sub psAddNewRow()
>
> Dim flag As Boolean = False
>
>
>
> flag = True
>
> If flag = True Then
>
> Dim row As New HtmlControls.HtmlTableRow
>
> Dim td1 As New HtmlControls.HtmlTableCell
>
> Dim td2 As New HtmlControls.HtmlTableCell
>
> Dim td3 As New HtmlControls.HtmlTableCell
>
> Dim td4 As New HtmlControls.HtmlTableCell
>
> Dim td5 As New HtmlControls.HtmlTableCell
>
> Dim td6 As New HtmlControls.HtmlTableCell
>
> Dim td7 As New HtmlControls.HtmlTableCell
>
> Dim td8 As New HtmlControls.HtmlTableCell
>
> Dim td9 As New HtmlControls.HtmlTableCell
>
> Dim td10 As New HtmlControls.HtmlTableCell
>
> Dim td11 As New HtmlControls.HtmlTableCell
>
> Dim strHtml1 As String
>
> Dim strHtml2 As String
>
> strHtml1 = "<INPUT TYPE=\""Button\"" CLASS=\""but\""
> onClick=\""EditRow(this)\"" VALUE=\""Edit\"">"
>
> strHtml2 = "<INPUT TYPE=\""Button\"" CLASS=\""but\""
> onClick=\""DeleteRow(this)\"" VALUE=\""Delete\"">"
>
> td1.InnerHtml = "Order"
>
> td2.InnerHtml = "Order2"
>
> td3.InnerHtml = "Order3"
>
> td4.InnerHtml = "Order4"
>
> td5.InnerHtml = "Order5"
>
> td6.InnerHtml = "Order6"
>
> td7.InnerHtml = "Order7"
>
> td8.InnerHtml = "Order8"
>
> td9.InnerHtml = "Order9"
>
> 'td10.InnerHtml = strHtml1
>
> 'td11.InnerHtml = strHtml2
>
> row.Cells.Add(td1)
>
> row.Cells.Add(td2)
>
> row.Cells.Add(td3)
>
> row.Cells.Add(td4)
>
> row.Cells.Add(td5)
>
> row.Cells.Add(td6)
>
> row.Cells.Add(td7)
>
> row.Cells.Add(td
>
> row.Cells.Add(td9)
>
> 'row.Cells.Add(td10)
>
> 'row.Cells.Add(td11)
>
> tblorederlist.Rows.Add(row) 'Add a row to table
>
> lblOrderOrPosition.Text = tblorederlist.Rows.Count
> --
> Thanks & Regards
> Valli
>
>
>

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      09-21-2007
Although you can add rows programmatically, it is very rear when you should
or have to do this. The way to go is using one of the databound controls
GridView, Repeater or DataList. That is their job to make tables.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


"Valli" <(E-Mail Removed)> wrote in message
news:udpAGmB$(E-Mail Removed)...
> Hi,
>
> I am a fresher to asp.net programming.
>
> I want to add rows to html table dynamically. I am able to do this
> using javascript.
> But i need to add rows to table in aspx.vb page. The oding what i

wrote
> adds a row to a table but doesnt display the record.
>
> When I retrieve value from the cell, it returns the value. Is there
> anything wroing in my coding.
> Please help me friends.
>
> My code follows here:
> Private Sub psAddNewRow()
>
> Dim flag As Boolean = False
>
>
>
> flag = True
>
> If flag = True Then
>
> Dim row As New HtmlControls.HtmlTableRow
>
> Dim td1 As New HtmlControls.HtmlTableCell
>
> Dim td2 As New HtmlControls.HtmlTableCell
>
> Dim td3 As New HtmlControls.HtmlTableCell
>
> Dim td4 As New HtmlControls.HtmlTableCell
>
> Dim td5 As New HtmlControls.HtmlTableCell
>
> Dim td6 As New HtmlControls.HtmlTableCell
>
> Dim td7 As New HtmlControls.HtmlTableCell
>
> Dim td8 As New HtmlControls.HtmlTableCell
>
> Dim td9 As New HtmlControls.HtmlTableCell
>
> Dim td10 As New HtmlControls.HtmlTableCell
>
> Dim td11 As New HtmlControls.HtmlTableCell
>
> Dim strHtml1 As String
>
> Dim strHtml2 As String
>
> strHtml1 = "<INPUT TYPE=\""Button\"" CLASS=\""but\""
> onClick=\""EditRow(this)\"" VALUE=\""Edit\"">"
>
> strHtml2 = "<INPUT TYPE=\""Button\"" CLASS=\""but\""
> onClick=\""DeleteRow(this)\"" VALUE=\""Delete\"">"
>
> td1.InnerHtml = "Order"
>
> td2.InnerHtml = "Order2"
>
> td3.InnerHtml = "Order3"
>
> td4.InnerHtml = "Order4"
>
> td5.InnerHtml = "Order5"
>
> td6.InnerHtml = "Order6"
>
> td7.InnerHtml = "Order7"
>
> td8.InnerHtml = "Order8"
>
> td9.InnerHtml = "Order9"
>
> 'td10.InnerHtml = strHtml1
>
> 'td11.InnerHtml = strHtml2
>
> row.Cells.Add(td1)
>
> row.Cells.Add(td2)
>
> row.Cells.Add(td3)
>
> row.Cells.Add(td4)
>
> row.Cells.Add(td5)
>
> row.Cells.Add(td6)
>
> row.Cells.Add(td7)
>
> row.Cells.Add(td
>
> row.Cells.Add(td9)
>
> 'row.Cells.Add(td10)
>
> 'row.Cells.Add(td11)
>
> tblorederlist.Rows.Add(row) 'Add a row to table
>
> lblOrderOrPosition.Text = tblorederlist.Rows.Count
> --
> Thanks & Regards
> Valli
>
>



 
Reply With Quote
 
Valli
Guest
Posts: n/a
 
      09-21-2007
Hi Shahzad,

Thanks for your answer.

I need to add an htmltablerow to html table cell. So I think the coding
which u gave will not suit my requirement.
According to my case, the row is getting added. When i return the count, it
reults with correct value.
But in display, the table doesn't show the added row.

Can you help me in this?

Regards
Valli

--
Regards
Valli
"Shahzad Ahmed" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Here is the code to solve your problem
>
> TableRow tr = new TableRow();
> TableCell tc1 = new TableCell();
> TableCell tc2 = new TableCell();
> tc1.Text = "tc1";
> tc2.Text = "tc2";
> tr.Cells.Add(tc1);
> tr.Cells.Add(tc2);
> this.Table1.Rows.Add(tr);
>
> Regards
> Shahzad
>
> "Valli" wrote:
>
>> Hi,
>>
>> I am a fresher to asp.net programming.
>>
>> I want to add rows to html table dynamically. I am able to do this
>> using javascript.
>> But i need to add rows to table in aspx.vb page. The oding what i
>> wrote
>> adds a row to a table but doesnt display the record.
>>
>> When I retrieve value from the cell, it returns the value. Is there
>> anything wroing in my coding.
>> Please help me friends.
>>
>> My code follows here:
>> Private Sub psAddNewRow()
>>
>> Dim flag As Boolean = False
>>
>>
>>
>> flag = True
>>
>> If flag = True Then
>>
>> Dim row As New HtmlControls.HtmlTableRow
>>
>> Dim td1 As New HtmlControls.HtmlTableCell
>>
>> Dim td2 As New HtmlControls.HtmlTableCell
>>
>> Dim td3 As New HtmlControls.HtmlTableCell
>>
>> Dim td4 As New HtmlControls.HtmlTableCell
>>
>> Dim td5 As New HtmlControls.HtmlTableCell
>>
>> Dim td6 As New HtmlControls.HtmlTableCell
>>
>> Dim td7 As New HtmlControls.HtmlTableCell
>>
>> Dim td8 As New HtmlControls.HtmlTableCell
>>
>> Dim td9 As New HtmlControls.HtmlTableCell
>>
>> Dim td10 As New HtmlControls.HtmlTableCell
>>
>> Dim td11 As New HtmlControls.HtmlTableCell
>>
>> Dim strHtml1 As String
>>
>> Dim strHtml2 As String
>>
>> strHtml1 = "<INPUT TYPE=\""Button\"" CLASS=\""but\""
>> onClick=\""EditRow(this)\"" VALUE=\""Edit\"">"
>>
>> strHtml2 = "<INPUT TYPE=\""Button\"" CLASS=\""but\""
>> onClick=\""DeleteRow(this)\"" VALUE=\""Delete\"">"
>>
>> td1.InnerHtml = "Order"
>>
>> td2.InnerHtml = "Order2"
>>
>> td3.InnerHtml = "Order3"
>>
>> td4.InnerHtml = "Order4"
>>
>> td5.InnerHtml = "Order5"
>>
>> td6.InnerHtml = "Order6"
>>
>> td7.InnerHtml = "Order7"
>>
>> td8.InnerHtml = "Order8"
>>
>> td9.InnerHtml = "Order9"
>>
>> 'td10.InnerHtml = strHtml1
>>
>> 'td11.InnerHtml = strHtml2
>>
>> row.Cells.Add(td1)
>>
>> row.Cells.Add(td2)
>>
>> row.Cells.Add(td3)
>>
>> row.Cells.Add(td4)
>>
>> row.Cells.Add(td5)
>>
>> row.Cells.Add(td6)
>>
>> row.Cells.Add(td7)
>>
>> row.Cells.Add(td
>>
>> row.Cells.Add(td9)
>>
>> 'row.Cells.Add(td10)
>>
>> 'row.Cells.Add(td11)
>>
>> tblorederlist.Rows.Add(row) 'Add a row to table
>>
>> lblOrderOrPosition.Text = tblorederlist.Rows.Count
>> --
>> Thanks & Regards
>> Valli
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving dynamically created table rows up and down in an HTML table T.G. Javascript 2 10-14-2008 12:56 PM
Dynamically adding rows to table web server control Geary ASP .Net 2 07-26-2007 01:03 PM
script for moving rows up and down and traverse thru rows of HTML table Subba Rao via DotNetMonster.com ASP .Net 0 03-19-2005 06:46 AM
Adding Rows Dynamically into the Table Web Control but only one row is getting inserted lucky ASP .Net 0 01-12-2005 10:45 AM
dynamically adding table rows and cells... Rob Meade ASP .Net 4 11-25-2003 12:11 PM



Advertisments