用vs2005 asp.net连接access数据库,查询数据的时候,页面刷新次就重新加载数据,数据越来越多(重复出现),请问这个如何解决,!ispostback加上也不行,比如删除一条数据后,在重新加载数据的话,数据就是在原来数据的基础上面在添加数据。请问这个如何解决~!
解决方案 »
- 存储过程中有output程序里面执行的时候会报错
- 大家看这代码,到底有没被入侵成功?2个技术员争得面红耳赤
- 没办法了,变通一下,我只想加一个判断,如果搞定了,则我还是用回freeTextBox控件吧! 唉! Fckeditor 找不到一个好的for ASP.NET的实例
- GridView的HyperLinkField能否直接window.open窗口
- 老板让做一个手机天线测试系统。。C/S架构的也可以。请问哪有参考资料。
- asp.net中, 怎么给ListBox绑定数据,数据来自数据库,listbox的值和文本来自表的两个字段
- 怎样把图片从数据库读出来和写进去(也就是上传以后写进数据库),高手指点一下
- 求ASP.NET GridView级联显示
- 谁有复合自定义控件的示例代码啊,求助,谢谢
- 100分求教:如何用ASP.NET实现框架页面?
- asp.net 采集器
- onserverclick 和 jquery的click
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Dat();
}
}
private void Dat()
{
D_User d = new D_User();
GridView1.DataSource = d.select();
GridView1.DataBind();
} protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = (this.GridView1.Rows[e.RowIndex].FindControl("Label1") as Label).Text;
string sql = "delete from usertable where ID='"+id+"'";
bool result = DBHelper.ExecuteSql(sql);
if (result == true)
{
Response.Write("<script>alert('删除数据成功!');</script>");
Dat();
}
else
{
Response.Write("<script>alert('删除数据失败!');</script>");
}
}
}
前台代码: <form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" Width="100%" OnRowDeleting="GridView1_RowDeleting">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="编号">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="logID" HeaderText="用户ID">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="password" HeaderText="性别">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="用户姓名">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="sex" HeaderText="性别">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="address" HeaderText="家庭住址">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="statename" HeaderText="职务">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderText="编辑" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
Text="编辑" ></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="删除" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
Text="删除" ></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</div>
</form>这个我觉得没什么问题,就是点删除数据的时候,数据会在删除这条数据之后再次在原来的基础上吗增加一倍,刷新页面也是在此增加一倍~!
不知道是数据库的问题呢还是什么的问题
{
string cmdName = e.CommandName;
int id = Convert.ToInt32(e.CommandArgument);
switch (cmdName)
{
case "SetOpenMoup":
OpenMpeSetSession(id);
break;
case "SetDel":
DelHouseType(id);
break;
default:
break;
}
}这种方法好控制。
<asp:LinkButton ID="lbtnDel" CommandArgument='<%# Eval("CFID")%>' CommandName="SetDel" runat="server" OnCommand="lbtnEdit_Command">删除</asp:LinkButton>这个也不行,好长时间没做web项目了,竟然出现这么多问题。还是最简单的问题。。
检查一下的数据源datatable如果是静态的,在赋值前先清除一次