views:

31

answers:

1

I have a gridview and when a user selects a row I want to change the view in my multiview and display several new gridviews. A user would be clicking on a computer, and then it will display the computer stats/atached devices/etc. The new gridviews are going to need a column from the row that was selected, how do I get that? Thanks.

+1  A: 

What language are you doing this on? I have done this in VB and C#.

  1. Create an actionlistener for the first gridview (FocusedRowChanged) so when the user selects the row in the first gridview it will be called letting you know that the selected a different row
  2. Within that listener you can find out which row was clicked on by using the arguments that it was sent (e) : e.FocusedRowHandle and then call a fetch on the second table.
  3. Next create another actionlistener on the dataset that fills the second gridview. (secondDataset_BeforeFetch). Within this fetch you grab the column you need from the selected row in the first column

    DataRow row = FirstGridView.GetFocusedDataRow();

    row2.ItemArray[indexOfWantedColumn];

  4. Finally within that actionlistener add the value you got in step 3 to the SqlCommand to send it with the fetch to fill the second gridview

    cmd.Parameters.AddWithValue("@parameterName", "valueToAdd");

    Where valueToAdd is the value you got from the DataRow in the 3rd step.

Kyra
My mistake, in vb.net
Shawn
Those code lines are in C#. But VB is very similar. If you need any more help feel free to ask
Kyra
Sorry but how do I make the actionlistener?
Shawn
Are you using a Visual Studio because if so you can go to the Design mode go to the properties of the grid and go to the events (lightening bolt) tab and find it in the list and double click it for them to add it. Otherwise in the code there are two popdown buttons at the top of the screen. On the left one choose the gridView and the right one to select the actionlistener you want.There is also http://www.java2s.com/Code/ASP/Asp-Control/AddactionlistenertoaserverButtonVBnet.htm tutorial page.
Kyra
yup, using visual studio, never used the events tab before, but the FocusedRowChanged event isn't in that list?
Shawn
SelectedIndexChanged maybe? Also, neither sender nor e have FocusedRowHandle, or any other functions assosciated with them besides the standard tostring/equals/gettype/etc?
Shawn
In your design right click on GridView (not the gridcontrol) and open the properties. Then if you click on the A->Z button and the lightening bolt and it will display all of the actionlisteners and you scroll down til you find FocusedRowChanged. in the blank to the right of it double-click and it will create the actionlistener function in your vb code and you just have to fill it in. The e argument should have the FocusedRowHandle.
Kyra
No FocusedRowChanged, but SelectedIndexChanged does the same thing and I just have to use the datakeys that I find in the gridview properties. Thanks!
Shawn
np :D If you need anymore help... :)
Kyra