0 Replies - 1143 Views - Last Post: 26 May 2014 - 10:56 AM Rate Topic: -----

#1 @imu#  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-May 14

dropdornlist using arraylist error

Posted 26 May 2014 - 10:56 AM

i m creating Album.aspx page but it geting error , How can i declare class veriable and create method in album class i m pointed my 2 Que below ddalbum_SelectedIndexChanged please help me to solve this
imu19310@gmail.com
using System;
public partial class Album : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lbreviewname.Visible = "false";
lbreviewdetails.Visible = "false";

if (Session["arrLstItems"] != null)
{
lbselectedalbums.DataSource = (ArrayList)Session["arrLstItems"];
lbselectedalbums.DataBind();
}
else
{
lbselectedalbums.Visible = false;
}
}
protected void btsave_Click(object sender, EventArgs e)
{
lbalreadyselected.Text = "";
lbselectedalbums.Visible = true;
selected = ddalbum.SelectedItem.Value;

if (!selected.Equals("Select Album"))
{
if (!ChkItemExit())
{
lbselectedalbums.Items.Add(selected);
}
else
{
lbalreadyselected.Text = "You have already selected this Album";
}
AddItemsInSession();
}
}
protected void ddalbum_SelectedIndexChanged(object sender, EventArgs e)
{
lbalreadyselected.Text = "";
lbreviewname.Visible = true;
lbreviewdetails.Visible = true;

if (ddalbum.SelectedItem.Value == "Salute")
{
lbreviewdetails.Text = "It is an awsome Album. The music has got lots of variation.";
}
else if (ddalbum.SelectedItem.Value == "Drum Circle")
{
lbreviewdetails.Text = "This Album is ok. The Music is not that good.";
}
else if (ddalbum.SelectedItem.Value == "Death Magnetic")
{
lbreviewdetails.Text = "This album is pathetic.";
}
else if (ddalbum.SelectedItem.Value == "Black")
{
lbreviewdetails.Text = "This album is Good.";
}
else
{
lbreviewdetails.Text = "";
lbreviewname.Visible = false;
}
}
/* 1] Declare the following class variables:
*
* ArrayList arrLstItems = new ArrayList();
* string Selected */

/* 2] Create the following methods in the Album class */
private void AddItemsInSession()
{
for (int index = 0; index < lbselectedalbums.Items.Count; index++)
{
string strItem = lbselectedalbums.Item[index].Text;
arrLstItems.Add(strItems);
}
Session[" arrLstItems"] = arrLstItems;
}
private bool ChItemExist()
{
string strSelectedItem = ddalbum.SelectedItem.Value;
bool blRetVal = false;
for (int index = 0; index < lbselectedalbums.Items.Count; index++)
{
string strListItem = lbselectedalbums.Items[index].Text;
if (string.Compare(strSelectedItem, strLstItem, false) == 0)
{
blRetVal = true;

}
}
return blRetVal;
}
}
Asp.net code Album.aspx Code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Album.aspx.cs" Inherits="Album" %>

<!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>

<table class="style1">
<tr>
<td align="left" valign="middle">
<asp:DropDownList ID="ddalbum" runat="server"
onselectedindexchanged="ddalbum_SelectedIndexChanged" >
<asp:ListItem>Select Album</asp:ListItem>
<asp:ListItem>Salute</asp:ListItem>
<asp:ListItem>Drum Circle</asp:ListItem>
<asp:ListItem>Death Magnetic</asp:ListItem>
<asp:ListItem>Black</asp:ListItem>
</asp:DropDownList>

<asp:Button ID="btsave" runat="server" Text="Save" onclick="btsave_Click" />
</td>
</tr>
<tr>
<td align="left" valign="middle"> <asp:Label ID="lbreviewname" runat="server" Text="Reviews" Font-Bold="True"
ForeColor="Red"></asp:Label>

<asp:Label ID="lbreviewdetails" runat="server" Text="Label"></asp:Label> <asp:Label ID="lbalreadyselected" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbselectedalbum" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:ListBox ID="lbselectedalbums" runat="server"></asp:ListBox>
</td> </tr>
</table>

</div>
</form>
</body>
</html>

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Page 1 of 1