i have an updated panel with a listview nested in it that is basicly a comment list.
then outside the listview i have a form that has a textebox and a button that adds the comment to the database
the expected behavior is that the update panel would be updated after adding the data to the DB using the onclick event with a manual .update() at the end.
then the data in the listview would simply update.
The problem is that the listview doesnt update properly. I need to do a 2nd update for the first to be shown.
Is my logic flawed? is there something i'm missing?
My initial impulse was to try it out and immediately put something together and it worked! I used mostly code. I do have an ajax update panel which does not interfere with the edit operation in any way shape or form. I tried a few things hoping to simulate
your problem without success. Now that I got your response I will try it wi LINQ.
One more question -- Are you using a LINQ DataSource control or are you coding your link expression. I need to know to same me work.
Partial Class AjaxListView
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindListView()
End If
End Sub
Private Sub BindListView()
Dim b As New BusinessRules.BusinessRules("Data Source=RAPTOR\SQLEXPRESS;Initial Catalog=AcmeData;Integrated Security=True")
ListView1.DataSource = b.GetData("Select blogid, blog, title, url from Blogs")
ListView1.DataBind()
End Sub
Protected Sub ListView1_ItemCanceling(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCancelEventArgs) Handles ListView1.ItemCanceling
ListView1.EditIndex = -1
BindListView()
End Sub
Protected Sub ListView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView1.ItemCommand
If e.CommandName = "Edit"Then
End If
End Sub
Protected Sub ListView1_ItemEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewEditEventArgs) Handles ListView1.ItemEditing
ListView1.EditIndex = e.NewEditIndex
BindListView()
End Sub
Protected Sub ListView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewUpdateEventArgs) Handles ListView1.ItemUpdating
'Override internal databound method
' call your own updating code here
'
e.Cancel = True
ListView1.EditIndex = -1
BindListView()
End Sub
Protected Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
End Sub
End Class
Well, I think is your code. I took basically the code I sent you earlier and everything is working fine. The only change I made to it is that I created a DataBase context and then build a query using LINQ and I was good to go. Everything worked!
Based on your initial post I think your problem is more basic. Look at events ItemCanceling and ItemEditing you need to to do a databind right after you change the listview mode. Also make sure that you page_load look something like mine. review this against
your code and if you can't figure it out just post your code and I will be glad to analyze it for you. Rest assured that it is not ajax or linq causing problems.
Partial Class AjaxListView
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindListView()
End If
End Sub
Private Sub BindListView()
Dim db As New ACMEDATADataContext
Dim bloglist = From b In db.Blogs _
Select b
ListView1.DataSource = bloglist
ListView1.DataBind()
End Sub
Protected Sub ListView1_ItemCanceling(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCancelEventArgs) Handles ListView1.ItemCanceling
ListView1.EditIndex = -1
BindListView()
End Sub
Protected Sub ListView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView1.ItemCommand
If e.CommandName = "Edit" Then
End If
End Sub
Protected Sub ListView1_ItemEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewEditEventArgs) Handles ListView1.ItemEditing
ListView1.EditIndex = e.NewEditIndex
BindListView()
End Sub
Protected Sub ListView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewUpdateEventArgs) Handles ListView1.ItemUpdating
'Override internal databound method
' call your own updating code here
'
e.Cancel = True
ListView1.EditIndex = -1
BindListView()
End Sub
Protected Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
End Sub
End Class
I have a ListView in which i need to implement the Insert, Update and delete operations.. using the Object datasource.. I need to create a handler for
OnItemInserting ,OnItemUpdating and
OnItemDeleting events of the List View.. how do i do this?
Siliticx
0 Points
3 Posts
Listview updating with updatepanel problem
May 04, 2008 06:11 PM|LINK
I have a weird problem (or a logic flaw...)
i have an updated panel with a listview nested in it that is basicly a comment list.
then outside the listview i have a form that has a textebox and a button that adds the comment to the database
the expected behavior is that the update panel would be updated after adding the data to the DB using the onclick event with a manual .update() at the end.
then the data in the listview would simply update.
The problem is that the listview doesnt update properly. I need to do a 2nd update for the first to be shown.
Is my logic flawed? is there something i'm missing?
updatepanel asp.net listview
JZoerman
Participant
847 Points
210 Posts
Re: Listview updating with updatepanel problem
May 04, 2008 07:06 PM|LINK
You have to update the listview control first, then the update panel. Re-bind the listview control and then execute UpdatePanel.update().
ListView.datasource = datasource
ListView.databind
UpdatePanel.update()
JZ
Sarasota Web Design
aamador
Contributor
5211 Points
1107 Posts
Re: Listview updating with updatepanel problem
May 04, 2008 07:20 PM|LINK
One question -- How are you performing databinding?
Siliticx
0 Points
3 Posts
Re: Listview updating with updatepanel problem
May 04, 2008 07:37 PM|LINK
In the page load using LINQ
aamador
Contributor
5211 Points
1107 Posts
Re: Listview updating with updatepanel problem
May 04, 2008 07:46 PM|LINK
My initial impulse was to try it out and immediately put something together and it worked! I used mostly code. I do have an ajax update panel which does not interfere with the edit operation in any way shape or form. I tried a few things hoping to simulate your problem without success. Now that I got your response I will try it wi LINQ.
One more question -- Are you using a LINQ DataSource control or are you coding your link expression. I need to know to same me work.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="AjaxListView.aspx.vb" Inherits="AjaxListView" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:ListView ID="ListView1" runat="server" DataKeyNames="BlogID"> <AlternatingItemTemplate> <tr style="background-color: #FFFFFF;color: #284775;"> <td> <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> </td> <td> <asp:Label ID="BlogIDLabel" runat="server" Text='<%# Eval("BlogID") %>' /> </td> <td> <asp:Label ID="BlogLabel" runat="server" Text='<%# Eval("Blog") %>' /> </td> <td> <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' /> </td> <td> <asp:Label ID="UrlLabel" runat="server" Text='<%# Eval("Url") %>' /> </td> </tr> </AlternatingItemTemplate> <LayoutTemplate> <table id="Table1" runat="server"> <tr id="Tr1" runat="server"> <td id="Td1" runat="server"> <table ID="itemPlaceholderContainer" runat="server" border="1" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;"> <tr id="Tr2" runat="server" style="background-color: #E0FFFF;color: #333333;"> <th id="Th1" runat="server"> </th> <th id="Th2" runat="server"> BlogID</th> <th id="Th3" runat="server"> Blog</th> <th id="Th4" runat="server"> Title</th> <th id="Th5" runat="server"> Url</th> </tr> <tr ID="itemPlaceholder" runat="server"> </tr> </table> </td> </tr> <tr id="Tr3" runat="server"> <td id="Td2" runat="server" style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF"> </td> </tr> </table> </LayoutTemplate> <InsertItemTemplate> <tr style=""> <td> <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" /> <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" /> </td> <td> <asp:TextBox ID="BlogIDTextBox" runat="server" Text='<%# Bind("BlogID") %>' /> </td> <td> <asp:TextBox ID="BlogTextBox" runat="server" Text='<%# Bind("Blog") %>' /> </td> <td> <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' /> </td> <td> <asp:TextBox ID="UrlTextBox" runat="server" Text='<%# Bind("Url") %>' /> </td> </tr> </InsertItemTemplate> <SelectedItemTemplate> <tr style="background-color: #E2DED6;font-weight: bold;color: #333333;"> <td> <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> </td> <td> <asp:Label ID="BlogIDLabel" runat="server" Text='<%# Eval("BlogID") %>' /> </td> <td> <asp:Label ID="BlogLabel" runat="server" Text='<%# Eval("Blog") %>' /> </td> <td> <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' /> </td> <td> <asp:Label ID="UrlLabel" runat="server" Text='<%# Eval("Url") %>' /> </td> </tr> </SelectedItemTemplate> <EmptyDataTemplate> <table id="Table2" runat="server" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;"> <tr> <td> No data was returned.</td> </tr> </table> </EmptyDataTemplate> <EditItemTemplate> <tr style="background-color: #999999;"> <td> <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" /> <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" /> </td> <td> <asp:Label ID="BlogIDLabel1" runat="server" Text='<%# Eval("BlogID") %>' /> </td> <td> <asp:TextBox ID="BlogTextBox" runat="server" Text='<%# Bind("Blog") %>' /> </td> <td> <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' /> </td> <td> <asp:TextBox ID="UrlTextBox" runat="server" Text='<%# Bind("Url") %>' /> </td> </tr> </EditItemTemplate> <ItemTemplate> <tr style="background-color: #E0FFFF;color: #333333;"> <td> <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> </td> <td> <asp:Label ID="BlogIDLabel" runat="server" Text='<%# Eval("BlogID") %>' /> </td> <td> <asp:Label ID="BlogLabel" runat="server" Text='<%# Eval("Blog") %>' /> </td> <td> <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' /> </td> <td> <asp:Label ID="UrlLabel" runat="server" Text='<%# Eval("Url") %>' /> </td> </tr> </ItemTemplate> </asp:ListView> </ContentTemplate> </asp:UpdatePanel> </form> </body> </html>Siliticx
0 Points
3 Posts
Re: Listview updating with updatepanel problem
May 04, 2008 07:55 PM|LINK
My linq data source is done by code
aamador
Contributor
5211 Points
1107 Posts
Re: Listview updating with updatepanel problem
May 04, 2008 08:39 PM|LINK
Well, I think is your code. I took basically the code I sent you earlier and everything is working fine. The only change I made to it is that I created a DataBase context and then build a query using LINQ and I was good to go. Everything worked!
Based on your initial post I think your problem is more basic. Look at events ItemCanceling and ItemEditing you need to to do a databind right after you change the listview mode. Also make sure that you page_load look something like mine. review this against your code and if you can't figure it out just post your code and I will be glad to analyze it for you. Rest assured that it is not ajax or linq causing problems.
Partial Class AjaxListView Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then BindListView() End If End Sub Private Sub BindListView() Dim db As New ACMEDATADataContext Dim bloglist = From b In db.Blogs _ Select b ListView1.DataSource = bloglist ListView1.DataBind() End Sub Protected Sub ListView1_ItemCanceling(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCancelEventArgs) Handles ListView1.ItemCanceling ListView1.EditIndex = -1 BindListView() End Sub Protected Sub ListView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView1.ItemCommand If e.CommandName = "Edit" Then End If End Sub Protected Sub ListView1_ItemEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewEditEventArgs) Handles ListView1.ItemEditing ListView1.EditIndex = e.NewEditIndex BindListView() End Sub Protected Sub ListView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewUpdateEventArgs) Handles ListView1.ItemUpdating 'Override internal databound method ' call your own updating code here ' e.Cancel = True ListView1.EditIndex = -1 BindListView() End Sub Protected Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged End Sub End ClassMcGuire
Member
67 Points
161 Posts
Re: Listview updating with updatepanel problem
Jul 31, 2008 03:34 PM|LINK
This is what I have been looking for...and in VB too!!!!! Thanks so much!!
J.R.R. Tolkien
ross_andrews
Member
4 Points
5 Posts
Listview......
Nov 21, 2008 05:17 AM|LINK
All,
I have a ListView in which i need to implement the Insert, Update and delete operations.. using the Object datasource.. I need to create a handler for OnItemInserting ,OnItemUpdating and OnItemDeleting events of the List View.. how do i do this?
plz help!
Ross