Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is possible to do an insert from the EmptyDataTemplate by handcrafting the insert. I am using a listview to display a static number of rows based on a unique filtered item. I am basically listing all the static attributes of an object. In the case where a new object is filtered on that does not have any attributes associated with it, i use the EmptyDataTemplate of the listview to display a HTMLTable that contains asp.net controls to capture data. I have a command button within the table that i evaluate using the ListView_ItemCommand. If the CommandName matches that of the "Insert" button within the EmptyDataItem, I use the ListView.Controls(0).FindControl method to locate my table. I then loop through my table and do inserts on the data found within each row. I included the how to find a control within the htmltable. In my code I am actually grabbing a bunch of controls then crafting the sql and using a SQLConnection to perform the insert.</p> <pre><code>Protected Sub ListView_ItemCommand(sender As Object, e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView.ItemCommand Select Case e.CommandName Case "Submit" Dim edt As HtmlTable = ListView.Controls(0).FindControl("myhtmltable") Dim ddl As DropDownList = CType(edt.FindControl("mydropdownlist"), DropDownList) 'Perform Insert Case "Some other commandname" End Select End Sub </code></pre> <p>You will need to still do error checking and databind() and refresh your listview.</p> <p>Is this the best way. Maybe not... But it is possible.</p> <p>~Ian</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload