Click here to Skip to main content
15,904,817 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
----here's my code from aspx file----

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="Inventory._default" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:FormView ID="FormView1" runat="server" DataKeyNames="ProductID"
            DataSourceID="dsProducts" DefaultMode="Insert"
            oniteminserted="FormView1_ItemInserted">
            <EditItemTemplate>
                ProductID:
                <asp:Label ID="ProductIDLabel1" runat="server"
                    Text='<%# Eval("ProductID") %>' />
                <br />
                ProductName:
                <asp:TextBox ID="ProductNameTextBox" runat="server"
                    Text='<%# Bind("ProductName") %>' />
                <br />
                Price:
                <asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>' />
                <br />
                CategoryID:
                <asp:TextBox ID="CategoryIDTextBox" runat="server"
                    Text='<%# Bind("CategoryID") %>' />
                <br />
                Category:
                <asp:TextBox ID="CategoryTextBox" runat="server"
                    Text='<%# Bind("Category") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server"
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <InsertItemTemplate>
                ProductName:
                <asp:TextBox ID="ProductNameTextBox" runat="server"
                    Text='<%# Bind("ProductName") %>' />
                <br />
                Price:
                <asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>' />
                <br />
                Category:
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                    DataSourceID="dsCategories" DataTextField="CategoryName"
                    DataValueField="CategoryID">
                </asp:DropDownList>
                <asp:EntityDataSource ID="dsCategories" runat="server"
                    ConnectionString="name=InventoryEntities"
                    DefaultContainerName="InventoryEntities" EnableFlattening="False"
                    EntitySetName="Categories" Select="it.[CategoryID], it.[CategoryName]">
                </asp:EntityDataSource>
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
                    CommandName="Insert" Text="Insert" />
&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
                    CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                ProductID:
                <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />
                <br />
                ProductName:
                <asp:Label ID="ProductNameLabel" runat="server"
                    Text='<%# Bind("ProductName") %>' />
                <br />
                Price:
                <asp:Label ID="PriceLabel" runat="server" Text='<%# Bind("Price") %>' />
                <br />
                CategoryID:
                <asp:Label ID="CategoryIDLabel" runat="server"
                    Text='<%# Bind("CategoryID") %>' />
                <br />
                Category:
                <asp:Label ID="CategoryLabel" runat="server" Text='<%# Bind("Category") %>' />
                <br />
                <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
                    CommandName="Edit" Text="Edit" />
                &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
                    CommandName="Delete" Text="Delete" />
                &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
                    CommandName="New" Text="New" />
            </ItemTemplate>
        </asp:FormView>
        <asp:EntityDataSource ID="dsProducts" runat="server"
            ConnectionString="name=InventoryEntities"
            DefaultContainerName="InventoryEntities" EnableDelete="True"
            EnableFlattening="False" EnableInsert="True" EnableUpdate="True"
            EntitySetName="Products">
        </asp:EntityDataSource>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            DataKeyNames="ProductID" DataSourceID="dsProducts">
            <Columns>
                <asp:BoundField DataField="ProductID" HeaderText="ProductID" ReadOnly="True"
                    SortExpression="ProductID" />
                <asp:BoundField DataField="ProductName" HeaderText="ProductName"
                    SortExpression="ProductName" />
                <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                <asp:BoundField DataField="CategoryID" HeaderText="CategoryID"
                    SortExpression="CategoryID" />
            </Columns>
        </asp:GridView>

    </div>
    </form>
</body>
</html>




-------------------------------------

----here's my code for my aspx.cs file----

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Inventory
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
        {
            GridView1.DataBind();
        }
    }
}


-------------------------------------

how solve this master need help. thanks in advance..
Posted
Comments
Sergey Alexandrovich Kryukov 24-Jun-12 21:30pm    
Not a question. What's the problem?
--SA

Hi,

Here is the similar discussion on your problem,

StackOverflow discussion[^]

PCReview discussion[^]

hope one of the solution from above discussion will work for you

thanks
-amit.
 
Share this answer
 
write your code on auto postback event.
 
Share this answer
 
Please follow the code..


C#
if(!ispostback)
{
  GridView1.DataBind();
}


Thanks
Ashish
 
Share this answer
 
Hi,
It is the property of asp.net that stores the controls value in viewstate. After inserting the data in database if you are clearing the controls data then also for some time the data will be there in viewstate. Only one solution of this problem is to remove viewstate after inserting the data. If you are able to clear viewstate then only you'll be able to solve this problem.

All the best.
--AK
 
Share this answer
 
Comments
newbie011292 25-Jun-12 15:38pm    
how should i do that?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900