|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
no FormView for create/insert pageHi;
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. 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.) This is great - thanks.
Show quoteHide quote "Steven Cheng[MSFT]" wrote: > 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.) > > 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.)
Access data in ObjectDataSource
Datagrid custom paging always loads page 1 Validation inside composite controls for ASP .NET 2.0 Datagrid cancel command does not work when adding new record custom button/link in detailsview commandfield section How to set default values for fields in detailsview problem traping event in child control must click button twice for event to fire style question Webcontrol Alignment problem |
|||||||||||||||||||||||