Asp. NET provides most data-bound controls that use additional markup to automatically encapsulate display data, for example, the GridView control displays its data in an HTML table (<table>), one row (<tr>) for each record, Each field is displayed as a cell (<td>), although you can customize the appearance of the GridView using the TemplateField component, but the output of the GridView is still limited to a table component. But sometimes you want to completely control the appearance of HTML tags produced by data-bound controls, which is the advantage of the ListView control, which is not using additional markup to encapsulate its output, but rather the exact HTML description you specify, You can specify precise markup by using a built-in template for the ListView control, and Table 1 lists the templates that are supported by the ListView control.
The code in the ASPX page:
<EditItemTemplate>
<asp Tutorial: DropDownList id= "DropDownList1" runat= "Server" >
<asp:listitem value= "Men" > Men </asp:ListItem>
<asp:listitem value= "female" > Female </asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
Adding events: ItemUpdating and ItemCreated events
protected void Listview1_itemupdating (object sender, Listviewupdateeventargs e)
{
Bind the DropDownList before updating
DropDownList Ddgender = (DropDownList) Listview1.items[e.itemindex]. FindControl ("DropDownList1");
e.newvalues["Gender"] = Ddgender.selectedvalue;
}
protected void listview1_itemcreated (object sender, ListViewItemEventArgs e)
{
if (E.item.itemtype = = Listviewitemtype.dataitem)
{
DropDownList Ddlgender = (DropDownList) e.item.findcontrol ("DropDownList1");
if (Ddlgender!= null)
{
Listviewdataitem Lvdataitem = (listviewdataitem) e.item;
DataRowView Rowview = (DataRowView) Lvdataitem.dataitem;
if (Rowview!= null)
{
var userrow = (datasetusers.usersrow) Rowview.row;
Ddlgender.selectedvalue = Userrow.gender;
}
}
}
}