private void Page_Load(object sender, System.EventArgs e)
{
ListBox1.DataSource = LoadGames();
ListBox1.DataTextField = "GameName";
ListBox1.DataValueField = "GameNumber";
ListBox1.DataBind();
}
change to
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{Return();}
ListBox1.DataSource = LoadGames();
ListBox1.DataTextField = "GameName";
ListBox1.DataValueField = "GameNumber";
ListBox1.DataBind();
}
On 11/10/05, teget1024 <[EMAIL PROTECTED]> wrote:
>
> I am working on an application where I want to populate a list, have
> teh user select one of the items and then act on that selection. I
> have created a list box and I populated it with text and values, but
> when I select an item from the list, the selected index does not
> change. I have tried multiple times, but each time the selected index
> does not change. I will post the list box definition and the c# code
> I am using below. I have gotten the code to execute the
> ListBox1_SelectedIndexChanged method, but the ListBox1.selectedIndex
> is always -1. Any help would be appreciated.
>
> ListBox Definition:
>
> <asp:ListBox id="ListBox1" style="Z-INDEX: 101; LEFT: 184px; POSITION:
> absolute; TOP: 168px"
> runat="server" Width="336px" AutoPostBack="True"></asp:ListBox>
>
>
> c# code:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
>
> ListBox1.DataSource = LoadGames();
> ListBox1.DataTextField = "GameName";
> ListBox1.DataValueField = "GameNumber";
> ListBox1.DataBind();
> }
>
>
> public SqlDataReader LoadGames()
> {
> SqlCommand myCommand;
> SqlDataReader myDataReader;
>
> sqlConnection1.Open();
> //prepare sql statements
> myCommand = new SqlCommand("SELECT * FROM Games WHERE
> NumberOfPlayers < MaxPlayers", sqlConnection1);
> myDataReader = myCommand.ExecuteReader(
> CommandBehavior.CloseConnection);
>
> return myDataReader;
> }
>
> private void ListBox1_SelectedIndexChanged(object sender,
> System.EventArgs e)
> {
>
> Label1.Text = "Fired";
> }
>
>
>
>
>
>
>
> SPONSORED LINKS
> Basic programming
> language<http://groups.yahoo.com/gads?t=ms&k=Basic+programming+language&w1=Basic+programming+language&w2=Computer+programming+languages&w3=Programming+languages&w4=Java+programming+language&c=4&s=126&.sig=bnac3LCZpttb3c9FvbVU-A>
> Computer
> programming
> languages<http://groups.yahoo.com/gads?t=ms&k=Computer+programming+languages&w1=Basic+programming+language&w2=Computer+programming+languages&w3=Programming+languages&w4=Java+programming+language&c=4&s=126&.sig=1Czd2hKCO9_u4KVZQperFQ>
> Programming
> languages<http://groups.yahoo.com/gads?t=ms&k=Programming+languages&w1=Basic+programming+language&w2=Computer+programming+languages&w3=Programming+languages&w4=Java+programming+language&c=4&s=126&.sig=TyHGCjod4YOKITrSq1xccQ>
> Java
> programming
> language<http://groups.yahoo.com/gads?t=ms&k=Java+programming+language&w1=Basic+programming+language&w2=Computer+programming+languages&w3=Programming+languages&w4=Java+programming+language&c=4&s=126&.sig=PZAexF9LyXpKb3HDJSlB1g>
> ------------------------------
> YAHOO! GROUPS LINKS
>
>
> - Visit your group
> "AspNetAnyQuestionIsOk<http://groups.yahoo.com/group/AspNetAnyQuestionIsOk>"
> on the web.
> - To unsubscribe from this group, send an email to:
> [EMAIL PROTECTED]<[EMAIL PROTECTED]>
> - Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/>.
>
>
> ------------------------------
>
[Non-text portions of this message have been removed]
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/