zoukankan      html  css  js  c++  java
  • 自己做的一个小功能~

    <%@ 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" DataSourceID="SqlDataSource1"
                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>
        剩余金币:<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>
        总金币:<asp:TextBox ID="totalScore" runat="server" Text="10"></asp:TextBox>
        剩余金币:<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")//点+
                {
                    TextBox txtbox = e.Item.FindControl("score") as TextBox;//手写输入框
                    int txtbox_val = Int32.Parse(txtbox.Text.ToString());//手写输入框的值
                    TextBox totalScore = e.Item.NamingContainer.NamingContainer.FindControl("totalScore") as TextBox;
                    //最外面的剩余金币
                    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());//总金币的值
                    int score = Int32.Parse(txtbox.Text.ToString());//手写输入框的值
                    int rs = shengyujinbi_1 != 0 ? score+1 : 0;
                    int shengyujinbi = totalScore_1 - 2;//剩余金币有点问题
                    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")//点减
                {
                    TextBox txtbox = e.Item.FindControl("score") as TextBox;//手写输入框
                    int txtbox_val = Int32.Parse(txtbox.Text.ToString());
                    TextBox totalScore = e.Item.NamingContainer.NamingContainer.FindControl("totalScore") as TextBox;
                    //最外面的剩余金币
                    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());//总金币的值
                    int score = Int32.Parse(txtbox.Text.ToString());//手写输入框的值
                    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);
                    }
                }
            }
        }
    }

    效果图

    image

    点击左边按钮是减,点击右边按钮是加,而且文本框的值不得超过总金币,无刷新的,嘿嘿。。。

    还发现有个文本框的判断没做,继续码字去。。。

    PS:QMM自己做的。。。

  • 相关阅读:
    C#.NET中的ToString()数字格式化
    Entity Framework实现属性映射约定
    CentOS6.3安装MySQL5.5
    Xshell传输文件
    centos直接yum安装nginx
    winform 开发中 把耗时操作 封装起来 异步执行(.net 4.0)
    c# action<> func<> 这2个委托怎么用和理解
    git@oschina使用入门(图形界面版)
    Linux任务前后台的切换
    linux 常用命令,开发记住这些基本能够玩转linux
  • 原文地址:https://www.cnblogs.com/QMM2008/p/4050380.html
Copyright © 2011-2022 走看看