Wednesday, March 21, 2012

Tabcontainer in formview - not inserting data

i am using a tabcontainer and panels inside the insertitemtemplate of a formview.

When i input text in the field and do an insert, a new record is created in the database, but the inputted fields are not processed??

If i place one textfield outside of the tabcontainer, the insert is working.

So, my question is: Is it not possible to use a tabcontainer IN a formview or do i need a workaround?

Maybe i just need to do it by inserting it manually, but then my question is, how do i get the inputted values from the formview?

Thanx for your help

Maurice

Hi Multje,

I had a similar issue when trying to use a dropdownlist bound to a sqldatasource AND the same dropdownlists selected value bound to the formview's datasource. I couldn't have it both ways, so I had to come up with a workaround.

Your situation is that the items in the tabcontainer would have to be referenced using the FindControl() method, which is not a built-in process in the formview... so your workaround will need to be similar to that which I used.

I put a hiddenfield in the formview, and when my dropdownlist selection changed, I put the selected item value into the hidden field. The formviews datasource was two-way bound to the hiddenfield, and not the dropdownlist itself.

What you will need to do is trigger the population of the hiddenfield's value in the formview when you do something within your tabcontainer. Get what I am saying? That way, the formview wont need to dig through the tabcontainer... it will use the hiddenfield. The hiddenfield will be populated by by your actions within the tabcontainer.


Hi,

thanx for the response.

I understand the workaround, however, in my case i dont have any dropdowns, just textboxes that are filled in by the user. I really cant understand why the formview, with the tabcontainer within in, containing the same fields as the formview normally has, databound and all, doesnt insert the values in the database? And the workaround in my case would be a lot of work to do, since my table has got about 35 fields to fill! That would mean i need 35 hidden fields as well??!!

There must be a better solution to this! :-)

Maurice


hi,

in code i found a way to make it work:

Protected

Sub BookTemplateDetail_OnIteminserting(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.FormViewInsertEventArgs)Handles BookTemplateDetail.ItemInserting
Dim pAsNew TextBox
Dim SelTabContainerAsNew TabContainer
Dim SelTabPanelAsNew TabPanel

e.Cancel =True
Try
SelTabContainer = BookTemplateDetail.FindControl("TabContainer1")
SelTabPanel = SelTabContainer.FindControl("TabPanel1")
p = SelTabPanel.FindControl("new_tbook_template_naamTextBox")
dbStatus.Text = p.Text
Catch exAs Exception
dbStatus.Text ="Failed!"
EndTry
EndSub

this works, but MY GOD! I have 30 fields on this form (on 3 tabpanels). Do i need to find all af them, put them in separate strings and then call the insert method??

Any suggestions?


Hello guys, i've found a solution

Protected

Sub FvLodge_ItemUpdating(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.FormViewUpdateEventArgs)Handles FvLodge.ItemUpdatingDim lodgeNombre, lodgeObservaciones, lodgePropiedadMLP, lodgeActivoAsStringDim lodgeNoches, lodgeHabitaciones, lodgeCapMaxHab, idUsuarioModificadorAsIntegerDim SelTabContainerAsNew TabContainerDim SelTabPanelAsNew TabPanelTry

SelTabContainer = FvLodge.FindControl(

"TbcDatosLodge")

SelTabPanel = SelTabContainer.FindControl(

"PnlDatos")

lodgeNombre =

CType(SelTabPanel.FindControl("TxtLodgeNombre"), TextBox).Text-->here i capture the value in the textbox that is inside the tabpanel

e.NewValues.Add(

"LodgeNombre", lodgeNombre) -->and here i pass that value as aNewValueto the collection of new values, is is important that the key name must be the same as in your update or insert queryCatch exAs Exception

e.Cancel =

TrueEndTryEndSub

hope this helps!..

No comments:

Post a Comment