hi everyone. i actually posted this already at forums.asp.net but got no answer. i would appreciate your guys help. thanks.
I have a databound ListView and am trying to dynamically add a databound textbox at run time. How can i data-bind it before adding it. This is my code so far:
Protected Sub lsvMain_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles lsvMain.PreRender
Dim tbl = CType(GetControl(Me, "tblMain"), HtmlTable)
Dim tbrInsert = CType(GetControl(Me, "tbrInsert"), HtmlTableRow)
Dim Fields = FieldList.Split(",")
Dim cll As HtmlTableCell
Dim txb As TextBox
For Each f In Fields
tbl.Rows(0).Cells.Add(New HtmlTableCell("th") With {.InnerText = f})
cll = New HtmlTableCell
txb = New TextBox '<<
txb.ID = "txb" & f '<<
cll.Controls.Add(txb) '<<
tbrInsert.Cells.Add(cll)
Next
End Sub
I would like to add something like txb.text="bind("firstname")" or something like that. I cannot figure out the syntax. neither could i find any info on the web.
I've been googling for hours, and the only remotely similar thing i found was this http://www.entechsolutions.com/DeveloperCorner/XWebSiteTemplate/Download.aspx which is FAR too complex for what i need.I will note that this is happening inside a usercontrol if it makes any difference
Otherwise the code is working precisely as planned, so far!
Thanks alot!!
update: i tried even going the manually way.by trying to fill the "values" collection of the listview via iteration. no go. heres my code
Protected Sub lsvMain_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewInsertEventArgs) Handles lsvMain.ItemInserting
For Each f In FieldList.Split(",")
e.Values.Add(f, CType(GetControl(lsvMain.InsertItem, ("txb" & f)), TextBox).Text)
Next
End Sub
but this too does not work. it seems that when this code runs, my dynamically added textboxes and cells are no more existent. ( i checked the controls collection for the row: empty)