Please i am trying to find out if its possible to select a row in a parent gridview and once that is selected....all the other rows in the Parent gridview is invisible...and the one i am working with is only seen on the gridview at that time.
I currently have a gridview binded to the database which is the parent and when its selected it post the child based on the ID.Now i have couple records on the gridview and once i select the one i need i want the others to be invinsible. so the one i am
working on will show alone. using visible="flase" will work for the whole Gridview,
Yeah... You kind of onpoint but not quite... You are right about the nested grid. and i can only see my child grid based on the selection i make on the parent grid. Now.... once i select a row from the Parent grid.....it will automatically show me the child
grid based on the selection
Now my point is... if i have five records on the parent grid and select one of the records.... i only want the selected row to show instead of all the other 4.... Currently its highlights the selected record. but i will like to make the other records invisible
while another record is seleted....
Thanks Sansan... Am so confused about your syntax.... i used it and it game me errors. The only thing i changed was the gridviewparent to its name on my code....My gridview name is "GridViewAll".... Could you please help write based on my gridview name....
my event handler is "Protected Sub GridviewAll_SelectIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs).....Thanks
Thanks Again Sansan, just so you know .. i am using asp 3.5 so my handler will not accept void but sub... when i put in the code... it does not allowe <GridviewRow> and the "a" and "b". i guess it needs to be declared. but i am woundering if it as to do
with the event handler. What do you think
Protected Sub GridViewAll_SelectedIndexChanged(sender As Object, e As EventArgs)
GridViewAll.Rows.OfType(Of GridViewRow)().ToList().Where(Function(a) a.RowIndex <> GridViewAll.SelectedIndex).ToList().ForEach(Function(b) b.Visible= False)
End Sub
oluts
Member
30 Points
299 Posts
GridView Select
Jun 26, 2010 04:44 PM|LINK
Please i am trying to find out if its possible to select a row in a parent gridview and once that is selected....all the other rows in the Parent gridview is invisible...and the one i am working with is only seen on the gridview at that time.
sansan
All-Star
53942 Points
8147 Posts
Re: GridView Select
Jun 26, 2010 05:08 PM|LINK
you can hide the other rows by setting Visible as false to other rows.
can you explain the requirement little more pls.
oluts
Member
30 Points
299 Posts
Re: GridView Select
Jun 26, 2010 05:32 PM|LINK
Alright,
I currently have a gridview binded to the database which is the parent and when its selected it post the child based on the ID.Now i have couple records on the gridview and once i select the one i need i want the others to be invinsible. so the one i am working on will show alone. using visible="flase" will work for the whole Gridview,
I hope you understand.
sansan
All-Star
53942 Points
8147 Posts
Re: GridView Select
Jun 26, 2010 06:42 PM|LINK
What I understood from your description was
You are using a nested gridview in which you are doing a postback to load some child gridview and once you select the row in the child gridview,
You want to hide the others.
You can do like this
find the Child gridview in the code behind and in the selectedIndexChangedEvent,
find the Gridviewrow selected and then
gv.Rows.OfType<GridViewRow>().ToList().Where(a=>a.RowIndex !=row.RowIndex).ToList().ForEach(b=>b.Visible=false)
it will get all the rows in teh child gridview and hide all rows except the row selected.
Correct me if I understood your requirement wrong.
oluts
Member
30 Points
299 Posts
Re: GridView Select
Jun 27, 2010 12:15 AM|LINK
Yeah... You kind of onpoint but not quite... You are right about the nested grid. and i can only see my child grid based on the selection i make on the parent grid. Now.... once i select a row from the Parent grid.....it will automatically show me the child grid based on the selection
Now my point is... if i have five records on the parent grid and select one of the records.... i only want the selected row to show instead of all the other 4.... Currently its highlights the selected record. but i will like to make the other records invisible while another record is seleted....
I hope i explained better this time around
sansan
All-Star
53942 Points
8147 Posts
Re: GridView Select
Jun 27, 2010 02:24 PM|LINK
In the Parent gridview selected index change event,
get the row index from e.CommandArgument and then you can do like this
gridviewParent.Rows.OfType<GridViewRow>().ToList().Where(a=>a.RowIndex !=selectedRowIndex.RowIndex).ToList().ForEach(b=>b.Visible=false)
That should get all rows except selected row and hide other rows.
oluts
Member
30 Points
299 Posts
Re: GridView Select
Jun 27, 2010 08:13 PM|LINK
Thanks Sansan... Am so confused about your syntax.... i used it and it game me errors. The only thing i changed was the gridviewparent to its name on my code....My gridview name is "GridViewAll".... Could you please help write based on my gridview name.... my event handler is "Protected Sub GridviewAll_SelectIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs).....Thanks
sansan
All-Star
53942 Points
8147 Posts
Re: GridView Select
Jun 27, 2010 08:34 PM|LINK
u can try like this
protected void GridViewAll_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewAll.Rows.OfType<GridViewRow>().ToList().
Where(a => a.RowIndex != GridViewAll.SelectedIndex).
ToList().ForEach(b => b.Visible = false);
}
Thanks
oluts
Member
30 Points
299 Posts
Re: GridView Select
Jun 27, 2010 08:56 PM|LINK
Thanks Again Sansan, just so you know .. i am using asp 3.5 so my handler will not accept void but sub... when i put in the code... it does not allowe <GridviewRow> and the "a" and "b". i guess it needs to be declared. but i am woundering if it as to do with the event handler. What do you think
sansan
All-Star
53942 Points
8147 Posts
Re: GridView Select
Jun 27, 2010 09:03 PM|LINK
If you are using C#,
add using System.Linq;
protected void GridViewAll_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewAll.Rows.OfType<GridViewRow>().ToList().
Where(a => a.RowIndex != GridViewAll.SelectedIndex).
ToList().ForEach(b => b.Visible = false);
}
If you are using VB,
add Imports System.Linq;