views:

87

answers:

5

i'm having a gridview which is binded to a dataview, OnPageLoad i'm populating gridview records. and i have a textbox and a button, So now i want to add more Records to GridView but this records should not be get added into DB, they just added to the page and of course the default records which are coming from db stay.

<asp:GridView id="gvItems" runat="server">
 <Columns>
   <asp:TemplateField HeaderText="Item Code" SortExpression="ItemCode">
      <ItemTemplate>
           <asp:Label runat="server" ID="lblIItemCode" Text='<%# Bind("ItemCode") %>' />
      </ItemTemplate>
   </asp:TemplateField>
 </Columns>
</asp:GridView>

VB.NET Code:

dvSCart = data.GetSCart(Session("SCartId"), 0, varFilterClause, errorStr)
gvItems.DataSource = dvSCart
gvItems.DataBind()

Basically at first Data From DB comes to page then after that Textbox data should get appended to the Gridview but Db should not get updated. i tried to do it by keeping DataView in ViewState or Session variable but later i came to know am going in a wrong way and that this won't work since Dataview can't be Serialized. i just need an idea or right path to do this, is this possible what am doing? may be i think jQuery will help, i googled for jQuery to do stuff but i failed or maybe i didn't understood since m a newbie to jQuery..

[my alternative option ]: create a temp db table and save it... but i don't want to use this option..

A: 

I'm still pretty new to .NET so take this with a "grain of salt"...

I think 'Bind' is a two way binding meaning data from the GridView's datasource is used to populate the grid and data entered into the GridView in edit mode will likewise populate the datasource. There is a one way binding directive called 'Eval' that I think might populate the grid without populating the datasource.

Another observation is that GridViews do not natively support insert operations so if you intend to allow new rows that do not come from the database you will have to add the insert controls and hook it up (or choose not to hook it up) to the data source yourself. I had a similar requirement where modifying the gridview was not supposed to modify the data source until an external 'Save' button was clicked. In my case I had an extra layer of business logic that served as the datasource. This business object data source represented a snapshot of the data base for the purposes of buffering changes made in the GridView until the 'Save' button was clicked. I was able to perserve this business object across postbacks by using the Session cache even though the business object was not serialiizable. I think it has to be serializable to store it in viewstate but maybe not session state. Maybe the viewstate is serialized and sent back and forth to the client whereas the session state is stored only on the server so doesn't need to be serialized.

Hope any of that helped.

Travis
hmm thnx dear...atleast i got an idea.. i'll try it..
FosterZ