ListView Insert

  • Thread starter Thread starter David C
  • Start date Start date
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 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")
{
...
 
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
 
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
 
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
 
Back
Top