d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Programming Help (gridview -> Listbox) > Aspnet, Msvd, C#
Add Reply New Topic New Poll
Member
Posts: 30,454
Joined: Aug 12 2008
Gold: 14,580.00
Sep 27 2012 08:28pm
Trying to get data from a Gridview and move it, if the "Select" button is pressed, to a Listbox.

So basically,
On button click, both Column_Description and Column_Value from the gridview need to be moved to the Listbox so I can use them in computations.

If anyone has any ideas, or can point me in the right direction, it'd be greatly appreciated. Google just isn't very helpful for this specific of an event.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 27 2012 08:32pm
your gridview should have a backend datasource, either a datatable or a List or other data structure. when your user presses the button, then remove the datasource from the gridview and set it on the listview
Member
Posts: 30,454
Joined: Aug 12 2008
Gold: 14,580.00
Sep 27 2012 08:35pm
Quote (carteblanche @ Sep 27 2012 10:32pm)
your gridview should have a backend datasource, either a datatable or a List or other data structure. when your user presses the button, then remove the datasource from the gridview and set it on the listview


That's what I'm having trouble doing. I cant find the line of code :/
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 27 2012 08:38pm
Quote (XLordxInfamousX @ Sep 27 2012 10:35pm)
That's what I'm having trouble doing. I cant find the line of code :/


List mydata;
void onPageLoad(Object sender, EventArgs e){
mydata = getData();
mygridview.datasource = mydata;
}

public void onButtonClick(Object sender, EventArgs e){
mylistview.Datasource = mydata;
mygridview.datasource = null;
}
something to that effect?

This post was edited by carteblanche on Sep 27 2012 08:50pm
Member
Posts: 30,454
Joined: Aug 12 2008
Gold: 14,580.00
Sep 27 2012 09:01pm
Quote (carteblanche @ Sep 27 2012 10:38pm)
List mydata = getData();
mylistview.Datasource  = mydata;
mygridview.datasource = null;

something to that effect?


Okay, I get where that's coming from.
I wasn't entirely clear.
I'm trying to move JUST the selected row of data when the button is clicked for THAT row.
Maybe this screenshot of the webpage will help convey what I need better ^_^

http://i.imgur.com/FKpCO.png
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 27 2012 09:09pm
Quote (XLordxInfamousX @ Sep 27 2012 11:01pm)
Okay, I get where that's coming from.
I wasn't entirely clear.
I'm trying to move JUST the selected row of data when the button is clicked for THAT row.
Maybe this screenshot of the webpage will help convey what I need better ^_^

http://i.imgur.com/FKpCO.png


selectedRow = mygridview.selectedIndex;

List selectedSnacks = new List();
selectedSnacks.add(mygridview.items[selectedRow]);
mygridview.remove(selectedRow);
mylistview.datasource = selectedsnacks;


but if you're using a web app, i recommend changing database and refreshing.

void onButtonClick(..){
int selectedPkId = mygridview.items[mygridview.selectedIndex].snackId;
Utility.executeSql("insert into selectedSnacks(snackid) values (" + selectedPkId + ")");
List snacks = getSelectedSnacks();
mylistview.datasource = snacks;
}

and something similar to your snack choices
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll