no FormView for create/insert page

D

David Thielen

Hi;

As an experiment for one page I created just a bunch of controls on the page
- no FormView, etc. I use this page for both create & edit. This way I only
have every control once (no Item/EditItem) and all controls are accessable as
objects in the code behind.

It seems to work pretty nice. But the ASP API is definitely not designed
with this in mind. For example, there is no way to tie an ObjectDataSource to
the controls.
 
S

Steven Cheng[MSFT]

Hi Dave,

As for the ASP.NET webcontrols, they all support simple databinding without
using those template databinding control (such as FormView, GridView...).
So for your scenario, you can just declare a page variable(non-private) in
the page's code behind class which is of the dataobject type(contains the
data propertes you want to bound them to the controls on the page). Then,
in the page's aspx template, we can just databinding expression to bind the
data properties on the data object onto the controls in the page. e.g:

==========aspx=============
............................
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1"
runat="server"></asp:SqlDataSource>

</div>
<asp:Label ID="Label1" runat="server"
Text="CategoryID:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
category.CategoryID %>'></asp:TextBox><br />
<asp:Label ID="Label2" runat="server"
Text="CategoryName:"></asp:Label><asp:TextBox
ID="TextBox2" runat="server" Text='<%# category.CategoryName
%>'></asp:TextBox><br />
<asp:Label ID="Label3" runat="server"
Text="Description:"></asp:Label><asp:TextBox
ID="TextBox3" runat="server" Text='<%# category.Description
%>'></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
===================

==========code behind========
public partial class _Default : System.Web.UI.Page
{
protected CategoryDS.CategoriesDataTable dt;
protected CategoryDS.CategoriesRow category;


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CategoryDSTableAdapters.CategoriesTableAdapter ta = new
CategoryDSTableAdapters.CategoriesTableAdapter();

dt = ta.GetData();
category = dt.Rows[0] as CategoryDS.CategoriesRow;

Page.DataBind();
}
}
}
========================

# I call Page.DataBind so as to make all the databinding expression in the
page get evaluated (after I've populated the page member variable which
hold the dataobject for databinding).

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

You're welcome Dave,

Good luck!

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Similar Threads

FormView DataBinding in Insert mode 0
FormView and Master Page 0
FormView Insert Session value 1
FormView Insert 6
Help with Formview Please in AspNet 2.0 0
FormView 0
LINQ and FormView 0
LINQ and FormView 0

Members online

No members online now.

Forum statistics

Threads
474,135
Messages
2,570,783
Members
47,341
Latest member
hanifree

Latest Threads

Top