Default to Edit mode in ASP.NET 3.5 ListView

ListView control gives you the flexibility of control the layout of your form. But when it comes to setting a Edit page using ListView such as the one for DetailView, you will realize it does not come with DefaultMode. For ListView you use the EditIndex property to set to something then the Edit view will be rendered by default.

<asp:ListView ID="ListView1" runat="server"
                DataSourceID="ContactInfoDataSource" EditIndex="0" >

Note that EditIndex is zero based, below is the explanation from MSDN

You can use the EditIndex property to programmatically specify or determine which item in a ListView control to edit. When this property is set to the index of an item in the control, that item is displayed in edit mode. In edit mode, the item is rendered by using the EditItemTemplate template instead of the ItemTemplate template. You can populate the EditItemTemplate with data-bound controls to enable users to modify values for the item. To switch from edit mode to display mode, set this property to -1.

One thought on “Default to Edit mode in ASP.NET 3.5 ListView

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>