我在排序列表对象项目中遇到问题 [英] iam getting problem in sorted list object project
本文介绍了我在排序列表对象项目中遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在default.aspx.cs页面中遇到一个小问题
hi iam getting a small issue in default.aspx.cs page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
using System.Globalization;
using System.IO;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
namespace sortedlist
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SortedList s1 = new SortedList();
s1.Add ("01","C");
s1.Add ("04","sql server");
s1.Add ("03",".net");
s1.Add ("02","c++");
s1.Add ("06","java");
s1.Add ("05","oracle");
ListBox1.DataValueField="key";
ListBox1.DataTextField="value";
ListBox1.DataSource=s1;
ListBox1.DataBind ();
{
string c=string.Empty;
for (int t=0;i<ListBox1.Items.Count,i++)
{
if(ListBox1.Items[i].Selected)
{
c+=ListBox1.Items[i].Text+"<br/>ListBox1.Items[i].Value";
}
}
Label1.Text="Name:"+TextBox1.Text+"<br/> Selected Courses<br/>"+c;
}
}
}
}
}
推荐答案
< a href =http://en.wikipedia.org/wiki/Syntax_error> Syntax_error [ ^ ]
使用此更正后的代码..
Syntax_error[^]
Use this corrected code..
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SortedList s1 = new SortedList();
s1.Add("01", "C");
s1.Add("04", "sql server");
s1.Add("03", ".net");
s1.Add("02", "c++");
s1.Add("06", "java");
s1.Add("05", "oracle");
ListBox1.DataValueField = "key";
ListBox1.DataTextField = "value";
ListBox1.DataSource = s1;
ListBox1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string c = string.Empty;
for (int i = 0; i < ListBox1.Items.Count; i++)
if (ListBox1.Items[i].Selected)
c += ListBox1.Items[i].Text + "<br/>" + ListBox1.Items[i].Value;
Label1.Text = "Name:" + TextBox1.Text + "<br/> Selected Courses<br/>" + c;
}
ASPX:
ASPX:
<form id="form1" runat="server">
<asp:ListBox SelectionMode="Multiple" ID="ListBox1" runat="server"></asp:ListBox>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" Text="Submit" runat="server" OnClick="Button1_Click" />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
</form>
这篇关于我在排序列表对象项目中遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文