<% @ Page Language = "C #" autoeventwireup = "true" codebehind = "webform14.aspx. cs" inherits = "bbs. webform14" %>
<! 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">
<Asp: scriptmanager id = "scriptmanager" runat = "server"> </ASP: scriptmanager>
<Div>
<Asp: updatepanel id = "updatepanel" runat = "server" updatemode = "Conditional">
<Contenttemplate>
<Asp: repeater id = "Repeater" runat = "server" performanceid = "sqlperformance1"
Onitemcommand = "repeater_itemcommand">
<Itemtemplate>
<Asp: imagebutton id = "jian" runat = "server" commandname = "jian" commandargument = "jian" imageurl = "images/4_left.png"/>
<Asp: textbox id = "score" runat = "server" text = "0"> </ASP: textbox>
Remaining gold coins: <asp: Label id = "shengyujinbi" runat = "server" text = "10"> </ASP: Label>
<Asp: imagebutton id = "jia" runat = "server" commandname = "jia" commandargument = "jia" imageurl = "images/4_right.png"/>
<Br/>
</Itemtemplate>
</ASP: repeater>
Total Gold Coins: <asp: textbox id = "totalscore" runat = "server" text = "10"> </ASP: textbox>
Remaining gold coins: <asp: textbox id = "shengyujinbi_wai" runat = "server" text = "10"> </ASP: textbox>
</Contenttemplate>
</ASP: updatepanel>
</Div>
<Asp: sqldatasource id = "sqldatasource1" runat = "server"
Connectionstring = "<% $ connectionstrings: wts_communityconnectionstring3 %>"
Selectcommand = "select * from [bbstopic]"> </ASP: sqldatasource>
</Form>
</Body>
</Html>
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Namespace BBS
{
Public partial class webform14: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
This. totalscore. textchanged + = new eventhandler (totalscore_textchanged );
}
Void totalscore_textchanged (Object sender, eventargs E)
{
}
Protected void repeater_itemcommand (Object source, repeatercommandeventargs E)
{
If (E. commandname = "jia") // point +
{
Textbox txtbox = E. Item. findcontrol ("score") as textbox; // handwritten input box
Int txtbox_val = int32.parse (txtbox. Text. tostring (); // value of the handwritten input box
Textbox totalscore = E. Item. namingcontainer. namingcontainer. findcontrol ("totalscore") as textbox;
// Remaining outermost gold coins
Textbox shengyujinbi_wai = E. Item. namingcontainer. namingcontainer. findcontrol ("shengyujinbi_wai") as textbox;
Int shengyujinbi_1 = int32.parse (shengyujinbi_wai.text.tostring (); // the value of the remaining outermost gold coin
Int totalscore_1 = int32.parse (totalscore. Text. tostring (); // The total value of the gold coin
Int score = int32.parse (txtbox. Text. tostring (); // The value of the handwritten input box.
Int rs = shengyujinbi_1! = 0? Score + 1: 0;
Int shengyujinbi = totalscore_1-2; // The remaining gold coins are faulty.
Label shengyujinbilbl = E. Item. findcontrol ("shengyujinbi") as label;
Shengyujinbilbl. Text = shengyujinbi. tostring ();
Txtbox. Text = Rs. tostring ();
Int val = shengyujinbi_1> 0? Shengyujinbi_1-1: 0;
Shengyujinbi_wai.text = convert. tostring (VAL );
For (INT I = 0; I <this. Repeater. Items. Count; I ++)
{
Label LBL = This. Repeater. items [I]. findcontrol ("shengyujinbi") as label;
LBL. Text = convert. tostring (VAL );
}
}
If (E. commandname = "jian") // point Subtraction
{
Textbox txtbox = E. Item. findcontrol ("score") as textbox; // handwritten input box
Int txtbox_val = int32.parse (txtbox. Text. tostring ());
Textbox totalscore = E. Item. namingcontainer. namingcontainer. findcontrol ("totalscore") as textbox;
// Remaining outermost gold coins
Textbox shengyujinbi_wai = E. Item. namingcontainer. namingcontainer. findcontrol ("shengyujinbi_wai") as textbox;
Int shengyujinbi_1 = int32.parse (shengyujinbi_wai.text.tostring ());
Int totalscore_1 = int32.parse (totalscore. Text. tostring (); // The total value of the gold coin
Int score = int32.parse (txtbox. Text. tostring (); // The value of the handwritten input box.
Int rs = score! = 0? Score-1: 0;
Label shengyujinbilbl = E. Item. findcontrol ("shengyujinbi") as label;
Shengyujinbilbl. Text = Rs. tostring ();
Txtbox. Text = Rs. tostring ();
Int val = shengyujinbi_1 <totalscore_1? Shengyujinbi_1 + 1: totalscore_1;
Shengyujinbi_wai.text = convert. tostring (VAL );
For (INT I = 0; I <this. Repeater. Items. Count; I ++)
{
Label LBL = This. Repeater. items [I]. findcontrol ("shengyujinbi") as label;
LBL. Text = convert. tostring (VAL );
}
}
}
}
}
Click the button on the left to subtract, click the button on the right to add, and the value of the text box cannot exceed the total gold coins, no refreshing, hey...
We also found that the judgment of a text box was not done. Continue with the code word...
PS: qmm self-made...
A small function made by myself ~