ASP:Table Problems

G

Guest

I am confused about the way in which asp:table objects work. When a control
is within an asp table it generally appears to be in the scope of the tables
parent control. E.g. if i have a page that consists of an asp table called
MyTable containing a textbox control call MyTextBox then i can access
MyTextBox directly from the PageLoad event handler without having to use
MyTable.FindControl(MyTextBox). MyTextBox can also be used for a control
paramter for an DataSourcecontrol that is outside of MyTable. In short ASP
table objects do not seem to impose the same kind of scoping restriction that
apply to data bound control such as DetalsView or GridvView.

However i have found that if you use an asp table object within a
TemplateField then place a control, that has been bound using <%#
Bind("FieldName") %> syntax, within that table, the two way databinding does
not work. It works as far as retreiving that data is concerned but as suu as
you try to insert or update data it treats all the values as null. If you
move the data bound controls outside tha asp table then updating and
inserting work fine. Deleting works fine even within the table.

I have got round this by using the ItemUpdating and ItemInserting event
handlers and pulling tha value out of the controls within the table and
putting them in e.NewValue and e.Values respectively.

What am i missing, why does two way databinding not work within an asp table
object.
 
T

Teemu Keiski

Hi,

it is basically the same thing. GridView and DetailsView are, yes, naming
containers where they "take" ownership of their child controls by being
their naming containers. What comes to databinding, with GridView when you
databind Container refers to the item of the control to which you databind
e.g GridViewRow. asp:table does not provide naming scopes, and it neither
has separare items to which you bind (e.g they'd be TableRows if comparing
semantically to GridView)

Basically asp:table is not databound control like GridView etc are, and
therefore two-way databinding doesn't work.
 
G

Guest

Perhaps i wasn't being clear as you seem to have missed my point entirely. I
am not trying to bind data to an ASP table. The asp table is within a
templatefield inside a databound FormView control. Within the asp table are
a number of textboxes DDLs etc bound to various fields using the <%#
Bind("FieldName") %> syntax. Data binding works perfectly for retreiving
data, but when i try to update or insert data i get an SQL exception telling
me various fields are null when they are not suposed to be. The controls
that are bound to these fields are not null at this point. If i move
textbox, ddls etc outside the asp table then the updates and inserts work
fine. Deleting works fine either way. I have tested that this occurs to
both a FormView and a DetailsView.

For clarity there are two examples below.

This markup does not work ...

<asp:FormView ID="MyformView" runat="server" DataKeyNames="SomeKeyfield"
DataSourceID="SomeDataSource">
<EditItemTemplate>
<asp:Table ID="tblEditSelectedRoute" runat="server">
<asp:TableRow>
<asp:TableCell>
<asp:TextBox ID="MyTextBox" runat="server" Text='<%# Bind("SomeField") %>
</asp:TextBox>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</EditItemTemplate>

This markup works fine...

<asp:FormView ID="MyformView" runat="server" DataKeyNames="SomeKeyfield"
DataSourceID="SomeDataSource">
<EditItemTemplate>
<asp:TextBox ID="MyTextBox" runat="server" Text='<%# Bind("SomeField") %>
</asp:TextBox>
<asp:Table ID="tblEditSelectedRoute" runat="server">
<asp:TableRow>
<asp:TableCell>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</EditItemTemplate>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top