accessing a itemdatabound handler for a nasted listview
I have a nested list view within a list view and i am trying to access its item data bound function but having no luck with it could anyone help me with this matter? ive also tried to use the outer listview's itemdatabound to do the things im trying to do but had no look. Thanks in advance :)
Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView1.ItemDataBound
'determins if you created the comment
If ListView1.EditIndex >= 0 Then
Dim dataItem As ListViewDataItem = CType(e.Item, ListViewDataItem)
If dataItem.DisplayIndex = ListView1.EditIndex Then
Dim postid As String = DirectCast(DataBinder.Eval(dataItem.DataItem, "Post"), String)
Dim commentTxt As TextBox = DirectCast(e.Item.FindControl("EditPostTxt"), TextBox)
commentTxt.Text = postid
End If
End If
Try
Dim GetdataItem As ListViewDataItem = CType(e.Item, ListViewDataItem)
Dim getPostId As Guid = DirectCast(DataBinder.Eval(GetdataItem.DataItem, "PostId"), Guid)
Dim listview As ListView = DirectCast(e.Item.FindControl("CommentsOnPosts"), ListView)
Dim loadcomments = From p In db.CommentPosts Where p.PostId = getPostId Select p.CommentPostId, p.PostId, p.aspnet_User.Tmp_Profile.DisaplyPictureSmall, fullname = p.aspnet_User.FirstName & " " & p.aspnet_User.LastName, profileid = p.aspnet_User.Tmp_Profile.ProfileId.ToString, p.Post, p.Date Order By [Date] Descending
listview.DataSource = loadcomments
listview.DataBind()
Try
cc.aloudToSeeDeleteSubPost(e, User.Identity.Name, "CommentDeleteTxt", "CommentEditTxt")
Catch ex As Exception
a.Show(ex.ToString)
End Try
Catch ex As Exception
a.Show(ex.ToString)
End Try
cc.aloudToSeeDelete(e, User.Identity.Name, "linkbutton1", "linkbutton2")
End Sub
Public Sub aloudToSeeDeleteSubPost(ByVal e As ListViewItemEventArgs, ByVal username As String, ByVal DelButton As String, ByVal editBut As String)
If e.Item.ItemType = ListViewItemType.DataItem Then
Dim dataItem As ListViewDataItem = DirectCast(e.Item, ListViewDataItem)
If dataItem.DataItem IsNot Nothing Then
Dim postid As Guid = DirectCast(DataBinder.Eval(dataItem.DataItem, "PostId"), Guid)
Dim getMessageFrom = (From p In db.CommentPosts Where p.PostId = postid).开发者_高级运维Single
If Not getMessageFrom.FromId = uif.returnUserID(username) Then
Dim DeleteButton As LinkButton = DirectCast(e.Item.FindControl(DelButton), LinkButton)
Dim EditButton As LinkButton = DirectCast(e.Item.FindControl(editBut), LinkButton)
DeleteButton.Visible = False
EditButton.Visible = False
End If
If getMessageFrom.ToId = uif.returnUserID(username) Then
Dim DeleteButton As LinkButton = DirectCast(e.Item.FindControl(DelButton), LinkButton)
DeleteButton.Visible = True
End If
End If
End If
End Sub
Put it in the ItemCreated
event
Dim listview As ListView = DirectCast(e.Item.FindControl("CommentsOnPosts"), ListView)
AddHandler listview.ItemDataBound, AddressOf ListViewCommentsOnPosts_ItemDataBound
精彩评论