【发布时间】:2013-05-28 03:14:38
【问题描述】:
我正在尝试在单击 asp:net 按钮时自动更新我的网格视图。我的 gridview 包含等待管理员验证的帐户。网格视图包含一个选择链接按钮。当管理员选择链接按钮并单击 asp:net 按钮时,假设会自动将“待定”更新为“已批准”。然后它会刷新 gridview 并自动删除已批准的待处理帐户。
我用了这个方法response.redirect方法
Response.Redirect("AdminVerify.aspx");
但它会立即刷新我的整个页面并忽略我的 ajax 脚本管理器
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
我已经添加了。使用脚本管理器,我认为它不会刷新整个页面。因此,我想知道如何让按钮在被点击后 3 秒后自动更新 gridview。 我尝试输入此 html 代码,但即使我没有单击任何内容,它也会每 5 秒自动刷新一次我的页面
<meta http-equiv="refresh" content="5" >
源代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.Master" AutoEventWireup="true" CodeBehind="AdminVerify.aspx.cs" Inherits="AdminWebApp.AdminVerify" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<p>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
Unverified Officer's Account Information<br />
<asp:GridView ID="GVVerify" runat="server" BackColor="#CCCCCC" BorderColor="#999999" Width="100%" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" ForeColor="Black" OnSelectedIndexChanged="GVVerify_SelectedIndexChanged" AutoGenerateSelectButton="True">
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<RowStyle BackColor="White" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
Officer ID :
<asp:Label ID="lblOID" runat="server"></asp:Label>
will be verify upon activation<br />
<br />
<asp:Label ID="lblMsg" runat="server"></asp:Label>
<br />
<br />
<asp:Button ID="btnVerify" runat="server" OnClick="btnVerify_Click" Text="Verify" />
<asp:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server"
TargetControlID="btnVerify"
ConfirmText="Are you sure you would like to verify this police officer?"
OnClientCancel="CancelClick" />
</ContentTemplate>
</asp:UpdatePanel>
</p>
</asp:Content>
后端代码:
public partial class AdminVerify : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source =localhost;" +
"Initial Catalog = project; Integrated Security = SSPI";
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("SELECT policeid, password, email, nric, fullname, contact, address, location From LoginRegisterPolice where pending='pending'", conn);
da.Fill(ds);
GVVerify.DataSource = ds;
GVVerify.DataBind();
conn.Close();
}
}
protected void GVVerify_SelectedIndexChanged(object sender, EventArgs e)
{
lblOID.Text = GVVerify.SelectedRow.Cells[1].Text;
}
protected void btnVerify_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=localhost; Initial Catalog=project; Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("Update LoginRegisterPolice set pending='approved' where policeid='"+lblOID.Text+"'", con);
cmd.ExecuteNonQuery();
lblMsg.Text = "The following officer has been verified.";
Response.Redirect("AdminVerify.aspx");
}
}
}
【问题讨论】:
-
按钮的作用是什么?只是经常更新它还是因为输入了会影响 Gridview 的新数据?
-
该按钮只是为了验证一些待处理的帐户。我已设置按钮将列从待处理更新为已批准。
-
您的按钮在哪里?它在 UpdatePanel1 内吗?显示代码你在按钮点击时做了什么
-
你能把你的完整代码贴在后面吗?