(v2003) Datagrid Dropdownlist Edit Problems

Discussion in 'ASP .Net' started by bh, Oct 19, 2006.

  1. bh

    bh Guest

    I'm trying to edit data in a datagrid through a dropdown list with different
    id/text values. The problem comes in when I click the edit button & nothing
    appears to be happening. Did I do something wrong in the EditItemTemplate
    or should I be binding, somehow, separately in the vb code? Please view my
    code, below, and the notes in green for clarification of what I've done, and
    what is/is not working, here. Thanks in advance.





    <asp:DataGrid id="dgItems" runat="server" CssClass="tablestandardsettings"
    BorderColor="Navy" AutoGenerateColumns="False">



    <Columns>



    <asp:TemplateColumn HeaderText="Available Items">

    <ItemTemplate> 'This works

    <asp:Label
    id="lbItem" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,
    "ItemName") %>' />

    </ItemTemplate>

    <EditItemTemplate> 'This
    does not work

    <asp:DropDownList
    id="cboItem" runat="server"

    DataSource='<%# dvItems %>'

    DataTextField="ItemName"

    DataValueField="ItemID">

    </asp:DropDownList>

    </EditItemTemplate>

    </asp:TemplateColumn>



    <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="OK"
    CancelText="Cancel" EditText="Edit" />



    <asp:ButtonColumn Text="Delete" CommandName="Delete"/>



    </Columns>

    </asp:DataGrid>



    '----------------------------------------------------------

    'I bind & display the datagrid here, when a user checks a

    'box to maintain the items - THIS PART WORKS

    'The grid is displayed, & the items show in the item column

    '----------------------------------------------------------

    Private Sub chkItems_CheckedChanged(ByVal sender As System.Object, ByVal e
    As System.EventArgs) Handles chkItems.CheckedChanged

    If Me.chkItems.Checked Then

    Me.BindItemsToGrid()

    Me.pnlItemMaintenance.Visible = True

    Else

    Me.pnlItemMaintenance.Visible = False

    End If

    End Sub



    '----------------------------------------------------------

    'However, when edit is selected, the dataview is populated,

    'but the row never opens in edit mode (the drop-down list

    'and Update/Cancel Buttons are not displayed/opened).

    '----------------------------------------------------------

    Private Sub dgItems_EditCommand(ByVal source As Object, ByVal e As _

    System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
    dgItems.EditCommand



    BindItemsDropDownList() 'Populates dvItems - This works

    Dim lblItemLabel As Label = e.Item.FindControl("lblItem")

    Session("OldItem") = lblItemLabel.Text



    '----------------------------------------------------------

    'Tracing accurately shows information retrieved from the Dataview,

    'That should be bound to the data grid's dropdownlist

    '----------------------------------------------------------

    Trace.Write("Current Item: " & Session("OldItem"))

    Trace.Write("ID: " & CStr(dvItems.Table.Rows(e.Item.ItemIndex)("ItemID")))

    Trace.Write("Item: " &
    CStr(dvItems.Table.Rows(e.Item.ItemIndex)("ItemName")))



    '----------------------------------------------------------

    'HERE ARE THE TROUBLESOME PARTS:

    '----------------------------------------------------------

    '1) Setting the properties of the actual cboItem

    'dropdownlist in the grid: The following 2 lines generate

    'an instantiation error, but if I create an instance, then

    'it's separate from the actual item in the grid.

    '

    'Dim cboItemList As DropDownList = e.Item.FindControl("cboItem")

    'cboItemList.SelectedItem.Text = lblItemLabel.Text

    '----------------------------------------------------------

    '2) Row never opens for editing (even with above 2 lines

    ' removed):

    '----------------------------------------------------------

    Me. dgItems.EditItemIndex = e.Item.ItemIndex



    End Sub
     
    bh, Oct 19, 2006
    #1
    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. (=?iso-8859-1?Q?=AF=60=B7=2E=2E=2E=F8=A4=B0=60=B0=

    Aldec Riviera v2003.06.1059 WinNT2kXP - new

    (=?iso-8859-1?Q?=AF=60=B7=2E=2E=2E=F8=A4=B0=60=B0=, Oct 3, 2003, in forum: VHDL
    Replies:
    0
    Views:
    728
    (=?iso-8859-1?Q?=AF=60=B7=2E=2E=2E=F8=A4=B0=60=B0=
    Oct 3, 2003
  2. San Diego Guy
    Replies:
    0
    Views:
    571
    San Diego Guy
    Aug 7, 2003
  3. Schultz
    Replies:
    3
    Views:
    582
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Feb 14, 2005
  4. bh
    Replies:
    0
    Views:
    386
  5. Sharon McCarty
    Replies:
    0
    Views:
    273
    Sharon McCarty
    Nov 24, 2004
Loading...

Share This Page