|
|
|
หน้า Report ถ้ากด Approve แล้วผมอยากให้ ข้อมูลหายไปด้วยต้องทำยังไงคับ |
|
|
|
|
|
|
|
หน้า Report ผม อยากให้กด Approve เสร็จแล้ว Record นั้นหายไปด้วยหลังจาก Script ที่เด้งขึ้นให้กด OK อ่ะครับ รบกวน อีกหน่อยครับ
Report.aspx (C#)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="User_Login.Report" %>
<!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>
<link rel="Stylesheet" href="css/style.css" type="text/css" />
<script language="javascript" type="text/javascript">
function lnkApprove_Click() {
var strconfirm = confirm("คุณต้อง Approve? สิทธ์เพื่อให้ User เข้าใช้ Login");
if (strconfirm == true) {
return true;
} else {
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="lblStatus" runat="server"></asp:Label>
<div class="wrap-all">
<div class="wrap-head">
<br />
<asp:HyperLink ID="hplLogout" runat="server" NavigateUrl="~/Logout.aspx">LogOut</asp:HyperLink>
</div>
<div class="wrap-content">
<div class="content">
<asp:Repeater id="myRepeater" runat="server" OnItemCommand="myRepeater_ItemCommand" OnItemDataBound="myRepeater_ItemDataBound" >
<HeaderTemplate>
<table border="0" width="550" cellpadding="1" cellspacing="1">
<tr>
<th>Username</th>
<th>Lastname</th>
<th>Password</th>
<th>Address</th>
<th>Tel</th>
<th>Mobile</th>
<th>Email</th>
<th>Approve</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="#f2f2f2">
<td align="center"><asp:Label id="lblUsername" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "username") %>'></asp:Label></td>
<td><asp:Label id="lblLastname" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "lastname") %>'></asp:Label></td>
<td><asp:Label id="lblPassword" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "password") %>'></asp:Label></td>
<td align="center"><asp:Label id="lblAddress" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "address") %>'></asp:Label></td>
<td align="right"><asp:Label id="lblTel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "tel") %>'></asp:Label></td>
<td align="right"><asp:Label id="lblMobile" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "mobile") %>'></asp:Label></td>
<td align="right"><asp:Label id="lblEmail" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "email") %>'></asp:Label></td>
<td align="right"><asp:LinkButton id="lnkApprove" CommandName="Update" runat="server" Onclientclick="return lnkApprove_Click();" >Approve</asp:LinkButton></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor="#f2f2f2">
<td align="center"><asp:Label id="lblUsername" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "username") %>'></asp:Label></td>
<td><asp:Label id="lblLastname" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "lastname") %>'></asp:Label></td>
<td><asp:Label id="lblPassword" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "password") %>'></asp:Label></td>
<td align="center"><asp:Label id="lblAddress" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "address") %>'></asp:Label></td>
<td align="right"><asp:Label id="lblTel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "tel") %>'></asp:Label></td>
<td align="right"><asp:Label id="lblMobile" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "mobile") %>'></asp:Label></td>
<td align="right"><asp:Label id="lblEmail" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "email") %>'></asp:Label></td>
<td align="right"><asp:LinkButton id="lnkApprove" CommandName="Update" runat="server" Onclientclick="return lnkApprove_Click();">Approve</asp:LinkButton></td>
</tr>
</AlternatingItemTemplate>
</asp:Repeater>
</div>
</div>
</div>
</form>
</body>
</html>
Report.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace User_Login
{
public partial class Report : System.Web.UI.Page
{
SqlConnection objConn;
SqlCommand objCmd;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["strUser"] == null)
{
Response.Redirect("index.aspx");
Response.End();
}
else
{
this.lblStatus.Text = "Welcome [" + Session["strUser"] + "]";
}
///////////////////////////////////////////////////
String strConnString;
strConnString = "Data Source=NEWPROGRAMMER;Initial Catalog=customer;Integrated Security=True";
objConn = new SqlConnection(strConnString);
objConn.Open();
if (!Page.IsPostBack)
{
BindData();
}
}
protected void BindData()
{
String strSQL;
//Get Data//
strSQL = "SELECT * FROM register";
SqlDataReader dtReader;
objCmd = new SqlCommand(strSQL, objConn);
dtReader = objCmd.ExecuteReader();
//*** BindData to Repeater ***//
myRepeater.DataSource = dtReader;
myRepeater.DataBind();
dtReader.Close();
dtReader = null;
}
protected void Page_Unload()
{
objConn.Close();
objConn = null;
}
/////test test / ///
String strSQL;
protected void myRepeater_ItemCommand(Object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Update")
{
//*** Username ***//
Label lblUsername = (Label)(e.Item.FindControl("lblUsername"));
strSQL = "UPDATE register SET status = 1 WHERE username = '" +lblUsername.Text + "' ";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
BindData();
}
}
protected void myRepeater_ItemDataBound(Object sender, RepeaterItemEventArgs e)
{
//*** Username ***//
Label lblUsername = (Label)(e.Item.FindControl("lblUsername"));
if (lblUsername != null)
{
lblUsername.Text = (string)DataBinder.Eval(e.Item.DataItem, "username");
}
//*** Lastname ***//
Label lblLastname = (Label)(e.Item.FindControl("lblLastname"));
if (lblLastname != null)
{
lblLastname.Text = (string)DataBinder.Eval(e.Item.DataItem, "lastname");
}
//*** Password ***//
Label lblPassword = (Label)(e.Item.FindControl("lblPassword"));
if (lblPassword != null)
{
lblPassword.Text = (string)DataBinder.Eval(e.Item.DataItem, "password");
}
//*** Address ***//
Label lblAddress = (Label)(e.Item.FindControl("lblAddress"));
if (lblAddress != null)
{
lblAddress.Text = (string)DataBinder.Eval(e.Item.DataItem, "address");
}
//*** Tel ***//
Label lblTel = (Label)(e.Item.FindControl("lblTel"));
if (lblTel != null)
{
lblTel.Text = DataBinder.Eval(e.Item.DataItem, "tel").ToString();
}
//*** Mobile ***//
Label lblMobile = (Label)(e.Item.FindControl("lblMobile"));
if (lblMobile != null)
{
lblMobile.Text = DataBinder.Eval(e.Item.DataItem, "mobile").ToString();
}
//Email//
Label lblEmail = (Label)(e.Item.FindControl("lblEmail"));
if (lblEmail != null)
{
lblEmail.Text = DataBinder.Eval(e.Item.DataItem, "email").ToString();
}
//*** Approve ***//
LinkButton lnkApprove = (LinkButton)(e.Item.FindControl("lnkApprove"));
if (lnkApprove != null)
{
//lnkApprove.Attributes.Add("OnClick", "return confirm('Approve Record?');");
}
}
}
}
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), C#, VS 2010 (.NET 4.x)
|
|
|
|
|
|
Date :
2013-04-24 11:05:28 |
By :
offonepoint |
View :
817 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณน่าจะสร้างพวก Flag หรือ Status น่ะครับ จากนั้นค่อยนำเอามาเป็น เงื่อนไขการแสดงผล
|
|
|
|
|
Date :
2013-04-24 11:23:10 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|