码迷,mamicode.com
首页 > 其他好文 > 详细

自己做的一个小功能~

时间:2014-10-25 18:41:43      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   os   ar   for   sp   div   

<%@ 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);
                }
            }
        }
    }
}

 

效果图

bubuko.com,布布扣

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

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

PS:QMM自己做的。。。

自己做的一个小功能~

标签:style   blog   http   io   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/QMM2008/p/4050380.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!