By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,190 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,190 IT Pros & Developers. It's quick & easy.

ASP:Table Problems

P: n/a
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.
Jul 17 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"clickon" <cl*****@discussions.microsoft.comwrote in message
news:51**********************************@microsof t.com...
>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.

Jul 17 '06 #2

P: n/a
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>

"Teemu Keiski" wrote:
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.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"clickon" <cl*****@discussions.microsoft.comwrote in message
news:51**********************************@microsof t.com...
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.


Jul 17 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.