I've got a listview which inserts a record into the db from a textbox. When the item has been inserted, the page reloads and displays what was inserted above the textbox. I would like to disable this behaviour if possible, and can't seem to find how to do
it. Hoping someone here can point me in the right direction?
Thanks for your reply. I'm trying to implement your suggestion, but am having some difficulty... the name of the textbox is linkTextBox. When I try to type linkTextBox.Text anywhere in the code behind, linkTextBox does not show up in intellisense, and I
get various errors depending on where I place it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SiteDatabaseModel;
public partial class _SubmitLink : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void EntityDataSource1_Inserting(object sender, EntityDataSourceChangingEventArgs e)
{
} protected void EntityDataSource1_Inserted(object sender, EntityDataSourceChangedEventArgs e) {
} }
Where in the .cs file should I place linkTextBox.Text=""? Placing it in the EntityDataSource_Inserted method results in a "Only assignment, call, increment, decrement, and new object expressions can be used as a statement" error.
Yes, my textbox is empty too, but the control is printing the item I've just inserted above the textbox each time. Every time I insert a new item, it adds to the list - here is a screenshot to show what I mean. I have inserted the words One, Two, and Three.
Each time I click "Insert", the word is inserted into the database, and the page reloads with the list of words I have inserted growing larger above the textbox.
(I tried to insert a screenshot into this post, but it kept breaking, here is the url)
I've looked at the code and tried different things for hours, and have done much googling, all without success. Would be grateful for any more suggestions...
Hi, thanks for the reply. I actually sort of solved the problem by going a completely different route and not using a listview at all. I just took the values from some basic text boxes and inserted them, however now I have a different problem for which I
have started a new thread (as it is a new issue) here -
http://forums.asp.net/p/1773977/4851594.aspx/1?p=True&t=634658598081597518
Every time I insert a new item, it adds to the list - here is a screenshot to show what I mean. I have inserted the words One, Two, and Three. Each time I click "Insert", the word is inserted into the database, and the page reloads with the list of words I
have inserted growing larger above the textbox.
This is quite normal... what do you see wrong it?
B
Kindly mark this post as "Answer", if it helped you.
After Insert, ListView will databind again. It will get the new data. That will include the newly inserted record.
If you can somehow filter these out, they won't show.
Maybe elaborate a bit on why you want it. Makes it easier to come up with a nice working solution.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
mrpaulvoid
Member
14 Points
9 Posts
How to stop a ListView displaying inserted items
Feb 25, 2012 05:31 PM|LINK
Hello,
I've got a listview which inserts a record into the db from a textbox. When the item has been inserted, the page reloads and displays what was inserted above the textbox. I would like to disable this behaviour if possible, and can't seem to find how to do it. Hoping someone here can point me in the right direction?
Cheers
Paul.
basheerkal
Star
10672 Points
2426 Posts
Re: How to stop a ListView displaying inserted items
Feb 25, 2012 06:07 PM|LINK
Try..... will this work.
after completing isertion to DB, in code behind set YourTexBox.Text=""
B
(Talk less..Work more)
mrpaulvoid
Member
14 Points
9 Posts
Re: How to stop a ListView displaying inserted items
Feb 25, 2012 06:37 PM|LINK
Hi,
Thanks for your reply. I'm trying to implement your suggestion, but am having some difficulty... the name of the textbox is linkTextBox. When I try to type linkTextBox.Text anywhere in the code behind, linkTextBox does not show up in intellisense, and I get various errors depending on where I place it.
Here is the code:
SubmitLink.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="SubmitLink.aspx.cs" Inherits="_SubmitLink" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"> <!-- Column 1 start --> <asp:ListView ID="ListView1" runat="server" DataKeyNames="id" DataSourceID="EntityDataSource1" InsertItemPosition="LastItem"> <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="linkTextBox" runat="server" Text='<%# Bind("link") %>' /> </td> </tr> </InsertItemTemplate> <ItemTemplate> <tr style=""> <td> </td> <td> <asp:Label ID="linkLabel" runat="server" Text='<%# Eval("link") %>' /> </td> </tr> </ItemTemplate> <LayoutTemplate> <table runat="server"> <tr runat="server"> <td runat="server"> <table ID="itemPlaceholderContainer" runat="server" border="0" style=""> <tr runat="server" style=""> <th runat="server"> </th> <th runat="server"> link</th> </tr> <tr ID="itemPlaceholder" runat="server"> </tr> </table> </td> </tr> <tr runat="server"> <td runat="server" style=""> </td> </tr> </table> </LayoutTemplate> </asp:ListView> <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=SiteDatabaseEntities1" DefaultContainerName="SiteDatabaseEntities1" EnableFlattening="False" EnableInsert="True" EntitySetName="Submissions1" oninserting="EntityDataSource1_Inserting"> </asp:EntityDataSource> <!-- Column 1 end --> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="Sidebar" Runat="Server"> <!-- Column 2 start --> <!-- Column 2 end --> </asp:Content>SubmitLink.aspx.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using SiteDatabaseModel; public partial class _SubmitLink : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void EntityDataSource1_Inserting(object sender, EntityDataSourceChangingEventArgs e) { }
protected void EntityDataSource1_Inserted(object sender, EntityDataSourceChangedEventArgs e)
{
}
}
Where in the .cs file should I place linkTextBox.Text=""? Placing it in the EntityDataSource_Inserted method results in a "Only assignment, call, increment, decrement, and new object expressions can be used as a statement" error.
Thanks.
basheerkal
Star
10672 Points
2426 Posts
Re: How to stop a ListView displaying inserted items
Feb 26, 2012 02:44 AM|LINK
Hmmm....Your LinkTextBox is inside FormView,,in Insert Template???
I see Nothing wrong in your code..For me it inserts data properly and TextBox becomes empty.
B
(Talk less..Work more)
mrpaulvoid
Member
14 Points
9 Posts
Re: How to stop a ListView displaying inserted items
Feb 26, 2012 11:10 AM|LINK
Yes, my textbox is empty too, but the control is printing the item I've just inserted above the textbox each time. Every time I insert a new item, it adds to the list - here is a screenshot to show what I mean. I have inserted the words One, Two, and Three. Each time I click "Insert", the word is inserted into the database, and the page reloads with the list of words I have inserted growing larger above the textbox.
(I tried to insert a screenshot into this post, but it kept breaking, here is the url)
http://imgur.com/eUEaT
I've looked at the code and tried different things for hours, and have done much googling, all without success. Would be grateful for any more suggestions...
Thanks!
usman400
Contributor
3513 Points
721 Posts
Re: How to stop a ListView displaying inserted items
Feb 26, 2012 04:36 PM|LINK
// Try removing Text='<%# Eval("link") %>' from following: <asp:Label ID="linkLabel" runat="server" Text='<%# Eval("link") %>' />mrpaulvoid
Member
14 Points
9 Posts
Re: How to stop a ListView displaying inserted items
Feb 26, 2012 05:30 PM|LINK
Hi, thanks for the reply. I actually sort of solved the problem by going a completely different route and not using a listview at all. I just took the values from some basic text boxes and inserted them, however now I have a different problem for which I have started a new thread (as it is a new issue) here - http://forums.asp.net/p/1773977/4851594.aspx/1?p=True&t=634658598081597518
Thanks
basheerkal
Star
10672 Points
2426 Posts
Re: How to stop a ListView displaying inserted items
Feb 27, 2012 01:32 AM|LINK
This is quite normal... what do you see wrong it?
B
(Talk less..Work more)
superguppie
All-Star
48225 Points
8679 Posts
Re: How to stop a ListView displaying inserted items
Feb 28, 2012 12:49 PM|LINK
After Insert, ListView will databind again. It will get the new data. That will include the newly inserted record.
If you can somehow filter these out, they won't show.
Maybe elaborate a bit on why you want it. Makes it easier to come up with a nice working solution.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.