问题:当我在asp.net(C#)中刷新浏览器时总是插入数据 [英] problem:always inserting data when i refresh browser in asp.net(C#)
本文介绍了问题:当我在asp.net(C#)中刷新浏览器时总是插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
----这是我来自aspx文件的代码----
----here''s my code from aspx file----
<%@ 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" />
<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" />
<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" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete" />
<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----
-------------------------------------
----here''s my code for my aspx.cs file----
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..
-------------------------------------
how solve this master need help. thanks in advance..
推荐答案
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
谢谢
-amit.
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.
write your code on auto postback event.
write your code on auto postback event.
Please follow the code..
Please follow the code..
if(!ispostback)
{
GridView1.DataBind();
}
谢谢
灰烬
Thanks
Ashish
这篇关于问题:当我在asp.net(C#)中刷新浏览器时总是插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文