Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

DataList (ASP.NET 1.1)

  • 05-07-2006 11:25am
    #1
    Closed Accounts Posts: 4,943 ✭✭✭


    How can i easily and safely DEselect an item in a DataList? At the moment i have link buttons in both the Item template and SelectedItem template which fire a "select" command. Then using the OnItemCommand event, i set SelectedIndex = -1 if the currently select row is the same as the row that fired the event. However this doesn't work.

    I'd appreciate if anyone could fire up a small project and paste up working code which lets you select/deselect items in a DataList. It's driving me bananas!


Comments

  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    Specifically, this doesn't work:
    		private void dlistTransfer_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
    		{
    			if(e.CommandName == "select")
    			{
    				if(this.dlistTransfer.SelectedIndex == e.Item.ItemIndex)
    					this.dlistTransfer.SelectedIndex = -1;
    				else
    					this.dlistTransfer.SelectedIndex = e.Item.ItemIndex;
    
    				this.BindTransfer();
    			}
    		}
    

    Setting the SelectedIndex = e.Item.ItemIndex works fine. After postbacks, the correct index is stored and everything is highlighted correctly. But if i try setting to -1 (to deselect all items) on postback the previous value for SelectedIndex is there, and things are highlighted incorrectly. Is this not the right way to "unselect" things?


  • Closed Accounts Posts: 14 GiantCranes


    Please post the full page code and I will give it a try here


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    I figured it out a few hours after i posted it up. It came to me in a flash :p The "bug" was that i used the commandname "select" for my custom selecting code. What was happening is that i was picking up the "select" command in my code, but ASP.NET was then picking it up itself on the "selected index changed" event. This resulted in me trying to change the index to (for example) 5, but then as soon as my method was complete, ASP.NET would fire the SelectedIndexChanged event and change the index on me.

    The code works fine if i either change my commandname to "custom select" or just move my code into the "selectedindexchanged" handler. Twas a stupid bug :p


Advertisement