Cerebrus
unread,Aug 28, 2008, 2:18:59 AM8/28/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Quick and Dirty:
Note that I have created a constructor for your CustomObj class as
follows :
public CustomObj(int oID, string oName)
{
this.objId = oID;
this.objName = oName;
}
Page code:
---
IList<CustomObj> myList;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
myList = new List<CustomObj>();
myList.Add(new CustomObj(1, "One"));
myList.Add(new CustomObj(2, "Two"));
myList.Add(new CustomObj(3, "Three"));
myList.Add(new CustomObj(4, "Four"));
Bind();
}
}
private void Bind()
{
ListBox1.DataSource = myList;
ListBox1.DataTextField = "Name";
ListBox1.DataValueField = "BrandId";
ListBox1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder(50);
foreach (ListItem li in ListBox1.Items)
{
if (li.Selected == true)
{
sb.Append("Text - " + li.Text + ", ");
sb.Append("Value - " + li.Value + "; ");
sb.Append("<br />");
}
}
Response.Write(sb.ToString());
}
---