data binding - ASP.NET ListView with identical markup in EditItemTemplate and InsertItemTemplate -
I have a ListView that includes an EditItemTemplate and an InsertItemTemplate. Two forms share almost all of their markup, for example:
& lt; Asp: listview runat = "server" ... & gt; & Lt; Layouttemplate & gt; ... & lt; / Layouttemplate & gt; & Lt; ItemTemplate & gt; & Lt; P & gt; & Lt;% # Eval ("name")%> & Lt; / P & gt; & Lt; P & gt; & Lt;% # Eval ("title")%> & Lt; / P & gt; ... & lt; / Itemtemplate & gt; & Lt; Insertitemtemplate & gt; & Lt; P & gt; Name: & lt; Asp: textbox runat = server text = '& lt;% # bind ("name")%> / & Gt; & Lt; / P & gt; & Lt; P & gt; Title: & lt; Asp: textbox runat = server text = '& lt;% # bind ("title")% & gt; / & Gt; & Lt; / P & gt; ... & lt; Asp: button runat = server commandname = "insert" text = "save" /> & Lt; / Insertitemtemplate & gt; & Lt; Edititemtemplate & gt; & Lt; P & gt; Name: & lt; Asp: textbox runat = server text = '& lt;% # bind ("name")%> / & Gt; & Lt; / P & gt; & Lt; P & gt; Title: & lt; Asp: textbox runat = server text = '& lt;% # bind ("title")% & gt; / & Gt; & Lt; / P & gt; ... & lt; Asp: button runat = server commandname = "update" text = "save" /> & Lt; / Edititemtemplate & gt; & Lt; / ASP: List View & gt;
Of course, there's really a lot going on in the insert and edit templates (too many fields, formatting, verification, etc.), and I hate to keep it
& lt; Insertitemtemplate & gt; My first thought was to move all the shared markup into a user control (.ascx):
& lt; Custom: myform runat = server / & gt; & Lt; Asp: button runat = server commandname = "insert" text = "save" /> & Lt; / Insertitemtemplate & gt; & Lt; Edititemtemplate & gt; & Lt; Custom: myform runat = server / & gt; & Lt; Asp: button runat = server commandname = "update" text = "save" /> & Lt; / Edititemtemplate & gt; Unfortunately, the two-sided binding (text = '& lt;% # bind ("foo")%>') works only when the form is in user control (it does not carry data from control back into the database is).
To include an optional file, it will be necessary to move all the share markup. Server-side Classic is behind the ASP, but they still work in ASP.NET and can be useful in such situations, because the content of the file contained in it behaves just like markup on the page is done.
But the files contained in it still have a bit to be done, and their disadvantages (such as VisualStudio are not very comfortable with them). Is there any alternative?
I have created a custom list view that makes this simple if there is no one involved, EditItemTemplate Used for both:
Private sub-list view_init (e-mail as the object, in the form of a by object in the form of the object). Me.Init handles if Me.InsertItemTemplate is nothing then me. InsertItemTemplate = Me.EditItemTemplate End if End Sub
I have also created a custom "Save" button that changes my order name between "Update" and "Insert" as appropriate :
The Private Sub handles the SaveLinkButton_Click (byVal Sender as the object, as System.EventArgs as ByVal E). Dim_ListView Control as in Control LISTView = GetListView () If _ListView IsNot is nothing then Me.BindingContainer _ListView .EditItem then Me.CommandName = "Update" Else Me.CommandName = "End if End End End if End End"
(The GetListView function moves the parent of the button until this f Inds a ListView.)
This is - it is useful for anyone. / P>
Comments
Post a Comment