|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Changea buttoncommand for one record onlyusing the property builder. I added a 3rd column for "Confirm Delete". When the Delete button is clicked, it runs dg_ItemCommand, and changes the visible column to say "Confirm Delete". If user clicks on ConfirmDelete, it then runs the handler dg_DeleteCommand and deletes the record. The problem is that the column changes for every record so that every record displays "Confirm Delete", and I'd rather display it only on the record the user has clicked on. Does anyone know how to do this? My code is below. Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.ItemCommand If (e.CommandName = "ConfirmDelete") Then dg.Columns(1).Visible = False dg.Columns(2).Visible = True End If end sub Private Sub dg_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.DeleteCommand Dim strGuid As String strGuid = e.Item.Cells(1).Text Call DeleteRecord(strGuid, strTableName) dg.Columns(1).Visible = True dg.Columns(2).Visible = False End Sub <Columns> <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" HeaderText="Edit" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn> <asp:ButtonColumn Text="Delete" HeaderText="Delete" CommandName="ConfirmDelete"></asp:ButtonColumn> <asp:ButtonColumn Text="Confirm Delete" HeaderText="Confirm Delete" CommandName="Delete" Visible=false></asp:ButtonColumn> <asp:ButtonColumn Text="Copy" CommandName="Copy"></asp:ButtonColumn> <asp:BoundColumn Visible="False" DataField="ID" ReadOnly="True"></asp:BoundColumn> <asp:BoundColumn DataField="Yr" HeaderText="Year"></asp:BoundColumn> Hello,
I don't think you'll get the results you're looking for with this approach--setting the visibility would only work if you could hide rows selectively and somehow merge the columns visually. Here's a solution: keep what you have below, but delete the "Delete" column. Then change your ItemCommand event to the following (hope this works, haven't done VB in a while): If (e.CommandName = "ConfirmDelete") Then Dim lbtn As LinkButton lbtn = CType(e.Item.Cells(1).Controls(0), LinkButton) lbtn.Text = "Confirm Delete" lbtn.CommandName = "Delete" End If What happens is the first time the link is clicked, the ItemCommand event fires and changes the command from ConfirmDelete to Delete for that link only. Clicking the link again then fires your Delete event and you can do your bidness. So don't create two columns--instead use one and change the function of the selected link (in your Delete function you probably want to change the CommandName back to "ConfirmDelete"). - Mike Rock wrote: Show quoteHide quote > I have a datagrid with the standard Edit and Delete columns that you can add > using the property builder. I added a 3rd column for "Confirm Delete". > > When the Delete button is clicked, it runs dg_ItemCommand, and changes the > visible column to say "Confirm Delete". If user clicks on ConfirmDelete, it > then runs the handler dg_DeleteCommand and deletes the record. > > The problem is that the column changes for every record so that every record > displays "Confirm Delete", and I'd rather display it only on the record the > user has clicked on. > > Does anyone know how to do this? My code is below. > > Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As > System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.ItemCommand > > If (e.CommandName = "ConfirmDelete") Then > dg.Columns(1).Visible = False > dg.Columns(2).Visible = True > End If > > end sub > > > Private Sub dg_DeleteCommand(ByVal source As Object, ByVal e As > System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.DeleteCommand > > Dim strGuid As String > strGuid = e.Item.Cells(1).Text > Call DeleteRecord(strGuid, strTableName) > dg.Columns(1).Visible = True > dg.Columns(2).Visible = False > > End Sub > > > <Columns> > <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" > HeaderText="Edit" CancelText="Cancel" > EditText="Edit"></asp:EditCommandColumn> > <asp:ButtonColumn Text="Delete" HeaderText="Delete" > CommandName="ConfirmDelete"></asp:ButtonColumn> > <asp:ButtonColumn Text="Confirm Delete" HeaderText="Confirm Delete" > CommandName="Delete" Visible=false></asp:ButtonColumn> > <asp:ButtonColumn Text="Copy" CommandName="Copy"></asp:ButtonColumn> > <asp:BoundColumn Visible="False" DataField="ID" > ReadOnly="True"></asp:BoundColumn> > <asp:BoundColumn DataField="Yr" HeaderText="Year"></asp:BoundColumn> > > |
|||||||||||||||||||||||