ListView Insert

D

David C

I have a ListView control that is bound to a DataSource and I need to
recognize when I am in Insert mode and use code to setup my DropDownList
control selections. I am using the code below in the ItemDataBound event to
identify Edit mode and it works great.

'Get the item and row objects.
Dim dataItem As ListViewDataItem = CType(e.Item, ListViewDataItem)
Dim rowView As DataRowView = CType(dataItem.DataItem, DataRowView)

'Verify there is an item being edited.
If lvIncExpTrans.EditIndex >= 0 Then

' Check for an item in edit mode.
If dataItem.DisplayIndex = lvIncExpTrans.EditIndex Then
'all my edit row setup code is here...

End If
End If


For identifying Insert mode I am using code below but it does not appear to
be working.

If dataItem.ItemType = ListViewItemType.InsertItem Then


What should I be checking to see that my ListView is in Insert mode.
Thanks.

David
 
G

Guest

I have a ListView control that is bound to a DataSource and I need to
recognize when I am in Insert mode and use code to setup my DropDownList
control selections.  I am using the code below in the ItemDataBound event to
identify Edit mode and it works great.

        'Get the item and row objects.
        Dim dataItem As ListViewDataItem = CType(e.Item, ListViewDataItem)
        Dim rowView As DataRowView = CType(dataItem.DataItem, DataRowView)

        'Verify there is an item being edited.
        If lvIncExpTrans.EditIndex >= 0 Then

            ' Check for an item in edit mode.
            If dataItem.DisplayIndex = lvIncExpTrans.EditIndex Then
  'all my edit row setup code is here...

     End If
 End If

For identifying Insert mode I am using code below but it does not appear to
be working.

If dataItem.ItemType = ListViewItemType.InsertItem Then

What should I be checking to see that my ListView is in Insert mode.
Thanks.

David

I think you can use OnItemCommand event

protected void lvItems_ItemCommand(object sender,
ListViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
...
 
D

David C

I have a ListView control that is bound to a DataSource and I need to
recognize when I am in Insert mode and use code to setup my DropDownList
control selections. I am using the code below in the ItemDataBound event
to
identify Edit mode and it works great.

'Get the item and row objects.
Dim dataItem As ListViewDataItem = CType(e.Item, ListViewDataItem)
Dim rowView As DataRowView = CType(dataItem.DataItem, DataRowView)

'Verify there is an item being edited.
If lvIncExpTrans.EditIndex >= 0 Then

' Check for an item in edit mode.
If dataItem.DisplayIndex = lvIncExpTrans.EditIndex Then
'all my edit row setup code is here...

End If
End If

For identifying Insert mode I am using code below but it does not appear
to
be working.

If dataItem.ItemType = ListViewItemType.InsertItem Then

What should I be checking to see that my ListView is in Insert mode.
Thanks.

David

I think you can use OnItemCommand event

protected void lvItems_ItemCommand(object sender,
ListViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
...

Thanks, I will try that. Can I also set default values for that insert row
in there as well?

David
 
G

Guest

I think you can use OnItemCommand event

protected void lvItems_ItemCommand(object sender,
ListViewCommandEventArgs e)
{
    if (e.CommandName == "Insert")
    {
       ...

Thanks, I will try that. Can I also set default values for that insert row
in there as well?

David- Hide quoted text -

- Show quoted text -

ok, I think I got it now, please follow the following page

http://forums.asp.net/p/1361580/2819708.aspx

they suggest to check the InsertItemPosition property as follows:

protected void lvwComputerGroups_DataBound(object sender, EventArgs e)
{
if (lvwComputerGroups.InsertItemPosition !=
InsertItemPosition.None)
{
....FindControl("...");


}
}

Let me know if it works
 
D

David C

I think you can use OnItemCommand event

protected void lvItems_ItemCommand(object sender,
ListViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
...

Thanks, I will try that. Can I also set default values for that insert row
in there as well?

David- Hide quoted text -

- Show quoted text -

ok, I think I got it now, please follow the following page

http://forums.asp.net/p/1361580/2819708.aspx

they suggest to check the InsertItemPosition property as follows:

protected void lvwComputerGroups_DataBound(object sender, EventArgs e)
{
if (lvwComputerGroups.InsertItemPosition !=
InsertItemPosition.None)
{
....FindControl("...");


}
}

Let me know if it works

Yes, that worked. Thank you.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,056
Messages
2,570,443
Members
47,089
Latest member
Bobby2025b

Latest Threads

Top