ערכתי לאחרונה בתאריך 22.10.07 בשעה 14:45 בברכה, ronen333
היי חבר'ה.
ביגלל השביתות המורה שלי אמר לי לעשות פרויקט שכולל סשן ואפלקציה. והוא לא לימד את זה אז אני נתקל בהרבה בעיות.ניסתי לעשות דף שיוסיף לאפלקציה טקסט מTEXTBOX ואז בכל פעם שיפתחו את הדף יראו את הרשימה בLISTBOX. אני יודע שיותר הגיוני לעשות את זה בDB אבל ביקשו אפלקציה אז אני עושה אפלקציה.
התוכנית שלי היתה כזאת:לבנות אפלקציה שכל פעם משרשרת טקסט מהTEXTBOX עם פסיק אחרי, ואז להמיר את האפלקציה אל מחורזת על מנת להוסיף לLISTBOX את הטקסט המופרד בפסיקים, כלומר כל TEXT המופרד בפסיק הוא ITEM בפני עצמו בLISTBOX.
משום מה שאני רוצה לעבור אם לולאה למטרות חיפוש על המחרוזת זה לא מאפשר לי..
קבצים: (החלק העיקרי הוא כמובן בDEFAULT.ASPX.CS כל השאר זה על מנת שתבינו את מלוא התוכנית והבעיה תמונה בiF עם הST במקום הI).
default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="GT_TextBox" runat="server" Style="z-index: 100; left: 450px; position: absolute; top: 73px" Width="191px"></asp:TextBox> <asp:Button ID="bt_AddName1" runat="server" OnClick="bt_AddName1_Click" Style="z-index: 102; left: 666px; position: absolute; top: 73px" Text="Add to list" Width="72px" /> <asp:ListBox ID="XboxLiveList" runat="server" Height="246px" Style="z-index: 103; left: 449px; position: absolute; top: 152px" Width="191px"> </asp:ListBox> <asp:Label ID="Label1" runat="server" Style="z-index: 105; left: 361px; position: absolute; top: 74px" Text="GamerTag:" Width="59px"></asp:Label> </div> </form> </body> </html>
|
default.aspx.cs
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { Application.Add("GT",""); } Page.Response.Write("UserCount:"+Application.Get("UserCount").ToString()); } protected void bt_AddName1_Click(object sender, EventArgs e) { if (this.XboxLiveList.Items.FindByText(this.GT_TextBox.Text) == null) { Application.Add("GT", this.GT_TextBox.Text + ","); string st = Application.Get("GT").ToString(); int index = 0; string st2=""; for (int i = 0; i < st.Length; i++) { if (st[i] == ",") { for (int j = index; j < i; j++) { st2 += st[j]; } this.XboxLiveList.Items.Add(st2); index = i + 1; } } //this.XboxLiveList.Items.Add(this.GT_TextBox.Text); } } }
|
global.asax
<%@ Application Language="C#" %><script runat="server"> void Application_Start(object sender, EventArgs e) { // Code that runs on application startup Application.Add("UserCount", 0); } void Application_End(object sender, EventArgs e) { // Code that runs on application shutdown } void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs } void Session_Start(object sender, EventArgs e) { // Code that runs when a new session is started int usercount = int.Parse(Application.Get("UserCount").ToString()); usercount = usercount + 1; Application.Set("UserCount", usercount); } void Session_End(object sender, EventArgs e) { int usercount = int.Parse(Application.Get("UserCount").ToString()); usercount = usercount - 1; Application.Set("UserCount", usercount); // Code that runs when a session ends. // Note: The Session_End event is raised only when the sessionstate mode // is set to InProc in the Web.config file. If session mode is set to StateServer // or SQLServer, the event is not raised. } </script>
|
תודה רבה מראש לכל העוזרים!!

