JunkMan
asked on
Dynamic HTMLRow Control ViewState
Hi,
I've got a bit of a problem in here, i have a table in the HTML of the page named tblEmployees with no rows in it, i bind the table with two cells, one with a description and another with a textbox, all this is created dinamically.
my problem is when i do a postback the rows are not there, i recreate them and if i had entered any value into the textbox it gets lost, i've already done this before and it worked, now it's not.
I've tried set and unset the viewstate of the page but nothing...
any ideas?
Partial Code:
Page_load:
If not page.ispostback then
BindTable()
PopulateTable()
else
BindTable()
end if
function BindTable()
if tblEmployees.rows.count= 0 then
for each emp as employee in getallemployees
Dim r As New HtmlControls.HtmlTableRow
r.ID = emp.Id.ToString
Dim c1 As New HtmlControls.HtmlTableCell
Dim c2 As New HtmlControls.HtmlTableCell
c1.Width = "100%"
c1.Attributes.Add("class", "content")
c1.InnerHtml = emp.Name & " :"
r.Cells.Add(c1)
c2.Controls.Add(New TextBox)
r.Cells.Add(c2)
tblEmployees.Rows.Add(r)
next
end if
end function
function PopulateTable()
For Each r As HtmlTableRow In tblCertified.Rows
Dim emp As new Employee(CInt(r.ID))
If Not emp Is Nothing Then
CType(r.Cells(1).Controls( 0), TextBox).Text = emp.Salary.tostring
End If
Next
end function
I've got a bit of a problem in here, i have a table in the HTML of the page named tblEmployees with no rows in it, i bind the table with two cells, one with a description and another with a textbox, all this is created dinamically.
my problem is when i do a postback the rows are not there, i recreate them and if i had entered any value into the textbox it gets lost, i've already done this before and it worked, now it's not.
I've tried set and unset the viewstate of the page but nothing...
any ideas?
Partial Code:
Page_load:
If not page.ispostback then
BindTable()
PopulateTable()
else
BindTable()
end if
function BindTable()
if tblEmployees.rows.count= 0 then
for each emp as employee in getallemployees
Dim r As New HtmlControls.HtmlTableRow
r.ID = emp.Id.ToString
Dim c1 As New HtmlControls.HtmlTableCell
Dim c2 As New HtmlControls.HtmlTableCell
c1.Width = "100%"
c1.Attributes.Add("class",
c1.InnerHtml = emp.Name & " :"
r.Cells.Add(c1)
c2.Controls.Add(New TextBox)
r.Cells.Add(c2)
tblEmployees.Rows.Add(r)
next
end if
end function
function PopulateTable()
For Each r As HtmlTableRow In tblCertified.Rows
Dim emp As new Employee(CInt(r.ID))
If Not emp Is Nothing Then
CType(r.Cells(1).Controls(
End If
Next
end function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm desperate, i doesn't work also, i don't know why...
this code is not exacly the one that i have
i'm using it in a web user control, that is dinamically loaded on a aspx, can it have something to do with this?
this code is not exacly the one that i have
i'm using it in a web user control, that is dinamically loaded on a aspx, can it have something to do with this?
ASKER
I found a solution, but i don't think is the best one
instead of doing the bindtable on the page_load, i'm doing it on page_init, i son't think this is an apropriate solution to this but at least is working...
Any comments about this...
instead of doing the bindtable on the page_load, i'm doing it on page_init, i son't think this is an apropriate solution to this but at least is working...
Any comments about this...
ASKER
function PopulateTable()
For Each r As HtmlTableRow In tblEmployees.Rows
Dim emp As new Employee(CInt(r.ID))
If Not emp Is Nothing Then
CType(r.Cells(1).Controls(
End If
Next
end function