b.
アクションに基づいてイベントの実行を決定します。
protected void Page_Load(object sender, EventArgs e)
{
Conn.Open();
//Execute action
string Action = CommFun.Get_Safe_Str(Request["Action "]);
if (!IsPostBack)
{
if (Action == "")
{
rpt_Pro_Order_List_Bind();
}
else if (Action = = "Single_Review") //Click to review
{
lbtn_Audit_eShop_Price_Command();
}
else //Click to review in batches
{
btn_Batch_Review_eShop_Price();
}
}
}
After the Repeater binds the data, add the onclick attribute to the LinkButton to execute the page script code.
protected void rpt_Pro_Order_List_Bind()
{
……
this.rpt_Review.DataSource = Dt;
this.rpt_Review.DataBind();
for (int i = 0; i < this.rpt_Review.Items.Count; i )
{
LinkButton lbtn_Audit_eShop_Price = (LinkButton)this.rpt_Review.Items[i].FindControl("lbtn_Audit_eShop_Price");
if (Dt.Rows[i]["Audit_eShop_Price"].ToString() == "1 ")
{
lbtn_Audit_eShop_Price.Enabled = false;
lbtn_Audit_eShop_Price.Text = "Audited";
}
else
{
lbtn_Audit_eShop_Price.Enabled = true;
lbtn_Audit_eShop_Price.Attributes.Add("onclick",
"return lbtn_Audit_eShop_Price_Command(this, '" Dt.Rows[i]["OrderId"].ToString() "');");
}
}
}
[code]
2. Use Ajax to implement batch review without refreshing.
Note: The control used here must be an Html control, otherwise it will cause a postback. But server controls can also be used inside Repeater.
Here you only need to add an onclick attribute to input="btton" and execute the Ajax script directly.
The content of the script is as follows:
[code]
//Batch review
function Batch_Review()
{
if(!checkSelItem("OrderId","Please select an order!") ) return false;
if(!confirm("Are you sure you want to review?")) return false;
var OrderIds = ""; //Record all order numbers
var elements = document.getElementsByName(" OrderId");
for (var m=0; m < elements.length; m ){
if(m == elements.length - 1)
{
OrderIds = OrderIds elements[ m].value;
}
else
{
OrderIds = OrderIds elements[m].value ",";
}
}
var orderIdArr = OrderIds.split (',');
var newOrderIdStr = "";
var j = 0;//Record the number of selected orders
var position = "";//Record the selected order position
for(var i = 0;i{
var chk_Id = "OrderId_" orderIdArr[i];
if($_Id(chk_Id).checked)//Record selected order
{
if(i == orderIdArr.length - 1)
{
newOrderIdStr = orderIdArr[i];
position = i;
}
else
{
newOrderIdStr = orderIdArr[i] ",";
position = i ",";
}
j ;
}
}
newOrderIdStr = RemoveRightComma( newOrderIdStr);//The order number after removing the last comma
position = RemoveRightComma(position);//The position after removing the last comma
$.ajax({
type: "POST",
url: "AjaxTest.aspx",
data: { Order_Id_Arr: newOrderIdStr, Action: "Batch_Review" },
success: function(msg) {
if (msg != "") {
for(var k = 0 ;k{
var newOrderIdArr = newOrderIdStr.split(',');
var positionArr = position.split(',');
$_Id("OrderId_" newOrderIdArr[k]).disabled = "disabled";
if(parseInt(positionArr[k])<10)
{
$_Id("rpt_Review_ctl0" parseInt(positionArr [k]) "_lbtn_Audit_eShop_Price").innerHTML = "Audited";
$_Id("rpt_Review_ctl0" parseInt(positionArr[k]) "_lbtn_Audit_eShop_Price").disabled = "disabled";
}
else
{
$_Id("rpt_Review_ctl" parseInt(positionArr[k]) "_lbtn_Audit_eShop_Price").innerHTML = "Audited";
$_Id("rpt_Review_ctl" parseInt(positionArr[k]) " _lbtn_Audit_eShop_Price").disabled = "disabled";
}
}
}
}
})
return true;
}
//Remove the right comma
function RemoveRightComma(str)
{
if(str == "") return;
var i;
for(i = str.length-1;i>=0;i- -)
{
//charAt(i) takes the character at a certain position
if(str.charAt(i) != ",") break;
}
//interception String, substring(start,stop); The returned result does not include the last digit
str = str.substring(0,i 1);
return str;
}
This concludes the example explanation.
Final review ideas:
1. Single audit: When the page is initialized, add the onclick attribute to the audit button and execute the page script. After clicking the audit, the page_load event in the background selects the event to be executed based on the Action.
2. Batch audit: Add the onclick attribute to the batch audit button and execute the Ajax script. The page_load event in the background also selects the event to be executed based on the Action. Batch review buttons must be Html controls.