|
-
Aug 6th, 2004, 03:40 AM
#1
Thread Starter
PowerPoster
deleting records in DataList view
Hi there.
I have a datalist
in this there are some fields (obviously) that displays records details.
I have placed 2 button in it as well
1) delete
2) submit changes
when the user hits delete I wish to delete that record. Each record has a unique ID number.
The thing is, when i double click on the button, it doesnt displays it's click method, I guess its because im using ASP.NET and VB.NET etc...
Is there a way to do this? even maybe if i create a public/private method, then in ASP.NET/HTML tell it to do the onClick thing and call that method?
-
Aug 6th, 2004, 03:50 AM
#2
I'm at the exact same point you are. I'm using a DataList control, and I've figured out how to load it, but haven't been able to save it, update, or delete anything.
I did find this link, by the way:
http://www.ondotnet.com/pub/a/dotnet.../datalist.html
If it gives you a clue, then post your code and tell me how you did it.
-
Aug 6th, 2004, 03:57 AM
#3
Thread Starter
PowerPoster
yeh i tried that but everytime i run it i get a compilation error. because I have put an onClick event in the asp.net/html code on the button
everytime the page is loaded/executed i get the compilation error....
-
Aug 6th, 2004, 04:07 AM
#4
Show the code you're using.
-
Aug 6th, 2004, 04:11 AM
#5
Thread Starter
PowerPoster
hm
button is on datalist
then in asp/html:
Code:
...
...
<TD width="10%">
<asp:Button id="BtnSubmit" runat="server" Width="104px" Text="Submit Changes"></asp:Button>
<asp:Button id=deleteButton runat="server" Width="104px" Text="Delete Record" onClick = "DeleteRecord()" CommandName="delete" CommandArgument="<%# DataBinder.Eval(Container, "DataItem['id']" ) %>">
</asp:Button></TD>
...
...
in vb.net, made this method:
Code:
Public Sub DeleteRecord(ByVal sender As Object, ByVal e As DataListCommandEventArgs)
Response.Write("<br><br>skjgbsgbrg")
End Sub
error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30455: Argument not specified for parameter 'e' of 'Public Sub DeleteRecord(sender As Object, e As System.Web.UI.WebControls.DataListCommandEventArgs)'.
-
Aug 6th, 2004, 04:23 AM
#6
Thread Starter
PowerPoster
sorted!!!!!
in code:
Code:
Public Sub DeleteRecord(ByVal Source As Object, ByVal e As EventArgs)
End Sub
notice the params in the brackets
then in asp.net:
Code:
onClick = "DeleteRecord"

but now, how do i go about actually deleting the record?
-
Aug 6th, 2004, 04:36 AM
#7
Thread Starter
PowerPoster
oh! try this one also when using a datalist:
forget the onclick
in asp.net:
Code:
OnUpdateCommand="UpdateRecord" OnDeleteCommand="DeleteRecord"
[/code]
in vb.net
Code:
Public Sub DeleteRecord(ByVal Source As Object, ByVal e As DataListCommandEventArgs)
Response.Write("<br><br><br><br>Delete")
End Sub
Public Sub UpdateRecord(ByVal Source As Object, ByVal e As DataListCommandEventArgs)
Response.Write("<br><br><Br><Br>Update")
End Sub
End Class
-
Aug 6th, 2004, 07:45 AM
#8
****... looks like I've gotten something after all.
VB Code:
Dim int1 As Integer, int2 As Integer
For int1 = 0 To DataList1.Items.Count - 1
For int2 = 1 To (DataList1.Items(int1).Controls.Count - 4) Step 2
Response.Write(CType(DataList1.Items(int1).Controls(int2), TextBox).Text.ToString)
Next
Next
I do not know why I have to do a Step 2 in there. My setup is like this:
4 textboxes, followed by 1 command button in each row.
Apparently, the controls go in "2"s, so I have to do a step 2 there. This code retrieves the values. What you can do now, is to use this and update your dataset's rows or use a query.
Also, what I had to do was to name the textboxes at the end of the row like this:
VB Code:
btn11.Text = e.Item.ItemIndex.ToString
And so, I'd use the text of the button to determine which row I am. You can do the same:
VB Code:
Public Sub DeleteRecord(ByVal Source As Object, ByVal e As EventArgs)
Response.Write(CType(Source, Button).Text)
...
See what I mean?
This has to be one of the crudest piece-of-**** snippets of code I've written in my life. I feel like pouring steaming hot doggy poo over myself.
-
Aug 6th, 2004, 07:48 AM
#9
Thread Starter
PowerPoster
lol thanks 
but that doesnt actually delete the record :P but i will try it for seeing exactly what it gets out 
but iget the error when using this code that table 0 could not be found!
Code:
Dim dr As DataRow
dr = Ds1.Tables(0).Rows.Find(DataList1.DataKeys(e.Item.ItemIndex))
dr.Delete()
??
-
Aug 9th, 2004, 12:55 AM
#10
You can modify that code to get you the row() number and item() number in your dataset.
I don't know why you're getting an error for Table(0), though. Have you given the table a name?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|