B
bh
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
ataGrid 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
ropDownList
id="cboItem" runat="server"
DataSource='<%# dvItems %>'
DataTextField="ItemName"
DataValueField="ItemID">
</asp
ropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="OK"
CancelText="Cancel" EditText="Edit" />
<asp:ButtonColumn Text="Delete" CommandName="Delete"/>
</Columns>
</asp
ataGrid>
'----------------------------------------------------------
'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
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
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
id="cboItem" runat="server"
DataSource='<%# dvItems %>'
DataTextField="ItemName"
DataValueField="ItemID">
</asp
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="OK"
CancelText="Cancel" EditText="Edit" />
<asp:ButtonColumn Text="Delete" CommandName="Delete"/>
</Columns>
</asp
'----------------------------------------------------------
'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