Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Please help

 

I have a web form which has a datagrid contain whole bunch of textboxes and dropdownlists and a delete column bellow:

 

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

 

Can you show me how to write something in C# or Javascript to confirm users that they really want to delete that row in the datagrid. Any help would appreciate.

Posted

You have to do it in grid's ItemCreated event. I've made it for my dgPhotoGrid:

 

      Private Sub dgPhoto_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgPhoto.ItemCreated
           If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
               Dim _butDelete As Button = CType(e.Item.Cells(3).Controls(1), Button)
               _butDelete.Attributes.Add("onClick", "return(confirm('Are you sure to delete this photo?'));")
           End If
       End Sub

A man and a dog have an average of three legs.

Beaware of Statistics.

Posted

Delete Validation Datgrid

 

We don't create row by row, but use SQL Tables to bind data to the datagrid. Therefore, I can't find the itemcareated event.

 

Here is how we load the data

 

//Load the data into DataGrid

 

dgTCDetail.DataSource = GetData(int ID);

dgTCDetail.DataBind();

Posted
In the design window, double-click your data grid; the code window should appear. Select the data grid control from the objects combo list located at the top left of the code window. Next to the objects combo to the right is the methods/events combo. Select the YourDataGrid_ItemCreated event. Here's where you put the code.
Posted

You have to read a little bit how asp.net events work :D

 

Belive me that I'll do the same thing with data binding and this event fires for each row (not only that).

A man and a dog have an average of three legs.

Beaware of Statistics.

Posted

Please Help to convert this code into C#. Thank you so much

 

Private Sub dgPhoto_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgPhoto.ItemCreated

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then

Dim _butDelete As Button = CType(e.Item.Cells(3).Controls(1), Button)

_butDelete.Attributes.Add("onClick", "return(confirm('Are you sure to delete this photo?'));")

End If

End Sub

 

or

 

Sub dgPopularFAQs_ItemDataBound(sender as Object, e as DataGridItemEventArgs)

' First, make sure we're NOT dealing with a Header or Footer row

If e.Item.ItemType <> ListItemType.Header AND _

e.Item.ItemType <> ListItemType.Footer then

'Now, reference the LinkButton control that the Delete ButtonColumn

'has been rendered to

Dim deleteButton as PushButton = e.Item.Cells(0).Controls(0)

 

'We can now add the onclick event handler

deleteButton.Attributes("onclick") = "javascript:return " & _

"confirm('Are you sure you want to delete FAQ #" & _

DataBinder.Eval(e.Item.DataItem, "FAQID") & "?')"

End If

End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...