ListView Insert

Discussion in 'ASP .Net' started by David C, Oct 6, 2009.

  1. David C

    David C 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
    David C, Oct 6, 2009
    #1
    1. Advertising

  2. On Oct 6, 9:08 pm, "David C" <> wrote:
    > 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")
    {
    ...
    Alexey Smirnov, Oct 7, 2009
    #2
    1. Advertising

  3. David C

    David C Guest

    "Alexey Smirnov" <> wrote in message
    news:...
    On Oct 6, 9:08 pm, "David C" <> wrote:
    > 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
    David C, Oct 7, 2009
    #3
  4. On Oct 7, 9:19 pm, "David C" <> wrote:
    > "Alexey Smirnov" <> wrote in message
    >
    > news:...
    > On Oct 6, 9:08 pm, "David C" <> wrote:
    >
    >
    >
    >
    >
    > > 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- 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
    Alexey Smirnov, Oct 7, 2009
    #4
  5. David C

    David C Guest

    "Alexey Smirnov" <> wrote in message
    news:...
    On Oct 7, 9:19 pm, "David C" <> wrote:
    > "Alexey Smirnov" <> wrote in message
    >
    > news:...
    > On Oct 6, 9:08 pm, "David C" <> wrote:
    >
    >
    >
    >
    >
    > > 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- 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
    David C, Oct 11, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shapper
    Replies:
    4
    Views:
    10,425
    David
    Nov 20, 2008
  2. shapper

    ListView ... Update and Insert

    shapper, Feb 8, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    1,153
    shapper
    Feb 8, 2008
  3. shapper
    Replies:
    1
    Views:
    671
    shapper
    Feb 12, 2008
  4. Philip
    Replies:
    2
    Views:
    707
    Philip
    Jul 23, 2008
  5. .
    Replies:
    0
    Views:
    718
Loading...

Share This Page