How do I apply this to a DetailsView? I know it diesn't use RowDataBound, instead it uses DataBound. But what about the e.Row and RowDataBound...etc? Basically, how would this look if I wanted to apply this to a DetailView?
Protected Sub GridView1_RowDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
' reference the Delete LinkButton
Dim db As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton)
' Get information about the product bound to the row
Dim product As Northwind.ProductsRow = _
CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, _
Northwind.ProductsRow)
db.OnClientClick = String.Format( _
"return confirm('Are you certain you want to delete the {0} product?');", _
product.ProductName.Replace("'", "\'"))
End If
End Sub
In the DetailsView's DataBound event, it would be something like this -
For Each row As DetailsViewRow In DetailsView1.Rows
If row.RowType = DataControlRowType.DataRow Then
' reference the Delete LinkButton
Dim db As LinkButton = CType(row.Cells(0).Controls(0), LinkButton)
' Get information about the product bound to the row
Dim product As Northwind.ProductsRow = _
CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, _
Northwind.ProductsRow)
db.OnClientClick = String.Format( _
"return confirm('Are you certain you want to delete the {0} product?');", _
product.ProductName.Replace("'", "\'"))
End If
Next
thanks for the reply, but I think I want to use the exact code I showed but convert it to apply to the DetailsView because I know e.Row doesn't apply to a DetailsView. thanks
I get a message that 'Row' is not a member of 'System.EventArgs'....? Also, this is being applied to a SQL-DS, not Object-DS...if that makes any difference.
For Each row As DetailsViewRow In DetailsView1.Rows
If row.RowType = DataControlRowType.DataRow Then
' reference the Delete LinkButton
Dim db As LinkButton = CType(row.Cells(0).Controls(0), LinkButton)
' Get information about the product bound to the row
Dim product As DetailsViewRow = _
CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, _
DetailsViewRow)
db.OnClientClick = String.Format( _
"return confirm('Are you certain you want to delete the {0} product?');", _
product.InsNam.Replace("'", "\'"))
End If
Next
Your code should be in the detailsview databound event. So all together it should look like:
Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.DataBound
For Each row As DetailsViewRow In DetailsView1.Rows
If row.RowType = DataControlRowType.DataRow Then
' reference the Delete LinkButton
Dim db As LinkButton = CType(row.Cells(0).Controls(0), LinkButton)
' Get information about the product bound to the row
Dim product As Northwind.ProductsRow = _
CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, _
Northwind.ProductsRow)
db.OnClientClick = String.Format( _
"return confirm('Are you certain you want to delete the {0} product?');", _
product.ProductName.Replace("'", "\'"))
End If
Next
End Sub
with DetailsView1 being the ID of your detailsview.
I get the message in the statement - CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, _
DetailsViewRow)
I also get a message - " 'InsNam' is not a member of 'Sysytem.Web.UI.WebControls.DetailsViewRow' " at InsNam (which is a databound field in the DetailsView1).
Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.DataBound
For Each row As DetailsViewRow In DetailsView1.Rows
If row.RowType = DataControlRowType.DataRow Then
' reference the Delete LinkButton
Dim db As LinkButton = CType(row.Cells(0).Controls(0), LinkButton)
' Get information about the product bound to the row
Dim product As DetailsViewRow = _
CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, _
DetailsViewRow)
db.OnClientClick = String.Format( _
"return confirm('Are you certain you want to delete the {0} product?');", _
product.InsNam.Replace("'", "\'"))
End If
Next
End Sub
mjta
Member
324 Points
684 Posts
DetailsView confirm message
Apr 01, 2010 06:53 PM|LINK
How do I apply this to a DetailsView? I know it diesn't use RowDataBound, instead it uses DataBound. But what about the e.Row and RowDataBound...etc? Basically, how would this look if I wanted to apply this to a DetailView?
Protected Sub GridView1_RowDataBound(ByVal sender As Object, _ ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _ Handles GridView1.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then ' reference the Delete LinkButton Dim db As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton) ' Get information about the product bound to the row Dim product As Northwind.ProductsRow = _ CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, _ Northwind.ProductsRow) db.OnClientClick = String.Format( _ "return confirm('Are you certain you want to delete the {0} product?');", _ product.ProductName.Replace("'", "\'")) End If End Subkaran@dotnet
All-Star
26228 Points
4596 Posts
Re: DetailsView confirm message
Apr 01, 2010 06:57 PM|LINK
If you like you can integrate this with ajax as:
http://mattberseth.com/blog/2007/07/confirm_gridview_deletes_with.html
Karan
~ Blog ~
Remember To Mark The Post(s) That Helped You As The ANSWER
rivdiv
All-Star
16323 Points
2595 Posts
Re: DetailsView confirm message
Apr 01, 2010 07:16 PM|LINK
In the DetailsView's DataBound event, it would be something like this -
For Each row As DetailsViewRow In DetailsView1.Rows If row.RowType = DataControlRowType.DataRow Then ' reference the Delete LinkButton Dim db As LinkButton = CType(row.Cells(0).Controls(0), LinkButton) ' Get information about the product bound to the row Dim product As Northwind.ProductsRow = _ CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, _ Northwind.ProductsRow) db.OnClientClick = String.Format( _ "return confirm('Are you certain you want to delete the {0} product?');", _ product.ProductName.Replace("'", "\'")) End If Nextmjta
Member
324 Points
684 Posts
Re: DetailsView confirm message
Apr 01, 2010 07:19 PM|LINK
thanks for the reply, but I think I want to use the exact code I showed but convert it to apply to the DetailsView because I know e.Row doesn't apply to a DetailsView. thanks
rivdiv
All-Star
16323 Points
2595 Posts
Re: DetailsView confirm message
Apr 01, 2010 07:33 PM|LINK
That's the exact code - instead of using e.Row you do the foreach loop and use "row".
mjta
Member
324 Points
684 Posts
Re: DetailsView confirm message
Apr 01, 2010 07:44 PM|LINK
I get a message that 'Row' is not a member of 'System.EventArgs'....? Also, this is being applied to a SQL-DS, not Object-DS...if that makes any difference.
For Each row As DetailsViewRow In DetailsView1.Rows If row.RowType = DataControlRowType.DataRow Then ' reference the Delete LinkButton Dim db As LinkButton = CType(row.Cells(0).Controls(0), LinkButton) ' Get information about the product bound to the row Dim product As DetailsViewRow = _ CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, _ DetailsViewRow) db.OnClientClick = String.Format( _ "return confirm('Are you certain you want to delete the {0} product?');", _ product.InsNam.Replace("'", "\'")) End If Nextrivdiv
All-Star
16323 Points
2595 Posts
Re: DetailsView confirm message
Apr 01, 2010 08:29 PM|LINK
Your code should be in the detailsview databound event. So all together it should look like:
Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.DataBound For Each row As DetailsViewRow In DetailsView1.Rows If row.RowType = DataControlRowType.DataRow Then ' reference the Delete LinkButton Dim db As LinkButton = CType(row.Cells(0).Controls(0), LinkButton) ' Get information about the product bound to the row Dim product As Northwind.ProductsRow = _ CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, _ Northwind.ProductsRow) db.OnClientClick = String.Format( _ "return confirm('Are you certain you want to delete the {0} product?');", _ product.ProductName.Replace("'", "\'")) End If Next End Subwith DetailsView1 being the ID of your detailsview.
There shouldn't be any problem with this.
mjta
Member
324 Points
684 Posts
Re: DetailsView confirm message
Apr 01, 2010 09:25 PM|LINK
I do have it within the DataBound Event. But still get the message....
rivdiv
All-Star
16323 Points
2595 Posts
Re: DetailsView confirm message
Apr 01, 2010 09:30 PM|LINK
Where do you have "Row"? On which line are you getting that message? Can you post your code?
mjta
Member
324 Points
684 Posts
Re: DetailsView confirm message
Apr 02, 2010 02:09 PM|LINK
I get the message in the statement - CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, _
DetailsViewRow)
I also get a message - " 'InsNam' is not a member of 'Sysytem.Web.UI.WebControls.DetailsViewRow' " at InsNam (which is a databound field in the DetailsView1).
Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.DataBound For Each row As DetailsViewRow In DetailsView1.Rows If row.RowType = DataControlRowType.DataRow Then ' reference the Delete LinkButton Dim db As LinkButton = CType(row.Cells(0).Controls(0), LinkButton) ' Get information about the product bound to the row Dim product As DetailsViewRow = _ CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, _ DetailsViewRow) db.OnClientClick = String.Format( _ "return confirm('Are you certain you want to delete the {0} product?');", _ product.InsNam.Replace("'", "\'")) End If Next End Sub