Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > OnButtonClick make an individual cell visible/invisible?

Reply
Thread Tools

OnButtonClick make an individual cell visible/invisible?

 
 
Roy
Guest
Posts: n/a
 
      02-11-2005
What is the best way to approach this problem? I have a datagrid with
an imagebutton. When one clicks the imagebutton it triggers an onClick
sub which makes column 9 (a user control) visible or invisible. Only
problem is when one clicks the imagebutton on a specific row, I want
*only* that row's column 9 to appear or disappear.


********My imagebutton*******************
<asp:TemplateColumn><ItemTemplate>
<asp:ImageButton id="imagebutton1" runat="server"
AlternateText="ImageButton 1" ImageAlign="left"
ImageUrl="arrow_right.gif" OnClick="ImageButton_Click"/>
</ItemTemplate></asp:TemplateColumn>


*********My user control (row 9)*********
<asp:TemplateColumn Visible = "false">
<ItemTemplate><tr><td colspan="9">
<UC_Grid:Nested id="FVDGrid" x=<%# container.dataitem("vown")%> y=<%#
container.dataitem("van_no")%> runat="server" />
</td></tr></ItemTemplate>
</asp:TemplateColumn>


**********My click sub**********
Public Sub ImageButton_Click(sender As Object, e As
ImageClickEventArgs)
If MR_Grid.Columns(9).Visible = False Then
MR_Grid.Columns(9).Visible = True
Else
MR_Grid.Columns(9).Visible = False
End If
End Sub


I tried modifying the sub with the individual cell as seen below, but
that bombs out with your average "'Item' is not a member of
'System.Web.UI.ImageClickEventArgs'" error. Anyone have any clues on
how I can implement this functionality?

Public Sub ImageButton_Click(sender As Object, e As
ImageClickEventArgs)
If e.Item.Cells(9).Visible = False Then
e.Item.Cells(9).Visible = True
Else
e.Item.Cells(9).Visible = False
End If
End Sub

 
Reply With Quote
 
 
 
 
Roy
Guest
Posts: n/a
 
      02-11-2005
I should have mentioned this above... my current code does make column
9 visible/invisible when the button is clicked. But it makes *all* of
the datagrid's column 9's visible/invisible. I wish just the row
clicked to reveal or conceal it's column 9.

Thanks!

 
Reply With Quote
 
 
 
 
Stefano
Guest
Posts: n/a
 
      02-11-2005
Hi Roy,

I think you should put all inside a panel, or <div runat="server">, and then
set its visible property to false.

For example:

<asp:TemplateColumn Visible = "false">
<ItemTemplate><tr><td colspan="9">

<div id="mypanel" runat="server">

<UC_Grid:Nested id="FVDGrid" x=<%# container.dataitem("vown")%> y=<%#
container.dataitem("van_no")%> runat="server" />

</div>

</td></tr></ItemTemplate>
</asp:TemplateColumn>

Public Sub ImageButton_Click(sender As Object, e As
ImageClickEventArgs)
Dim mypanel as Control = MR_Grid.Columns(9).FindControl("mypanel")

If mypanel.Visible = False Then
mypanel.Visible = True
Else
mypanel.Visible = False
End If
End Sub

HTH

Bye,
Stefano

"Roy" <(E-Mail Removed)> ha scritto nel messaggio
news:(E-Mail Removed) oups.com...
> I should have mentioned this above... my current code does make column
> 9 visible/invisible when the button is clicked. But it makes *all* of
> the datagrid's column 9's visible/invisible. I wish just the row
> clicked to reveal or conceal it's column 9.
>
> Thanks!
>



 
Reply With Quote
 
Roy
Guest
Posts: n/a
 
      02-11-2005
Thanks for the reply Stefano, but the code doesn't work.

After some extensive tweaking of your code I can get the page to
display, but it always displays all the columns as hidden, regardless
of if I hit the imagebutton or not. At the end of the day, I think the
code above isn't the way to go as it still doesn't solve the problem of
telling the computer exactly which row's column should be
visible/invisible. MR_Grid.Columns(9).FindControl("mypanel") is still
broadly referencing all the grids columns to the compiler.

Any other thoughts?

 
Reply With Quote
 
Roy
Guest
Posts: n/a
 
      02-11-2005
I took out the Columns(9) part of your code above because FindControl
isn't a member of it and generates errors.

**********
Public Sub ImageButton_Click(sender As Object, e As
ImageClickEventArgs)
Dim mypanel as Control = MR_Grid.FindControl("mypanel")
If mypanel.Visible = False Then <<<<<<----ERROR HERE
mypanel.Visible = True
Else
mypanel.Visible = False
End If
End Sub
***********
Only problem now is that an error is generated as shown above. The
error is "Object reference not set to an instance of an object" which I
suspect is because the FindControl is not finding anything and setting
mypanel to null.

 
Reply With Quote
 
Roy
Guest
Posts: n/a
 
      02-11-2005
Correction. The .Visible property cannot be applied to a control (i.e.,
"mypanel").

SIGH

Maybe I should rename the thread "Social Security "crisis" solved!"
betcha I'd get a lot more input....

 
Reply With Quote
 
Roy
Guest
Posts: n/a
 
      02-11-2005
OK! Solved it...sorta...Behold the power of this FULLY OPERATIONAL
deathst---datagrid, I mean...

Public Sub ImageButton_Click(sender As Object, e As
ImageClickEventArgs)
If sender.Parent.Parent.Cells(9).Visible = False Then
sender.Parent.Parent.Cells(9).Visible = True
Else
sender.Parent.Parent.Cells(9).Visible = False
End If
End Sub

But here's the rub. No matter where I stick the visible="false" in the
datagrid, whether in the <TemplateColumn> tag or User Control tag it
always overrides the visible setting that the imagebutton_click
provides. Thus, if I remove the visible="false" from the .aspx page it
runs fine, openly and closing just the selected row I desired. The only
problem with that is that the default visible setting is now "true,"
which is something I don't want.

Soooo close.... tips anyone?

 
Reply With Quote
 
Roy
Guest
Posts: n/a
 
      02-12-2005
Don't mean to be a pest, but I have to ask a final time as I still
can't resolve this small issue...

Advice anyone?

 
Reply With Quote
 
Danny
Guest
Posts: n/a
 
      02-14-2005
Here's my two cents. I think Stefano's idea was close...but the
problem is your making the id of that <div> tag the same for every
row....so when you do the Columns(9).findControl() it returns that
control from each row.

You could try to find a way to change the ID of that <div> tag for each
row, and then do the FindControl() with that ID that is unique.

You could try using the primary key of the data you get from the
database and sticking it in there - and find that Control....

-OR-

Remembering back to our posts on the MSDN managed newsgroup...

http://msdn.microsoft.com/newsgroups...f-700d941c8e3d

This problem you are having is pretty much the reason why I use the
Selected Index and/or the EditItemIndex property. That's a good way
to get that one specific row.

Here's one thing you could try:

1. In the <aspataGrid id="MR_Grid"..... > tag, add the
attribute OnSelectedIndexChanged="MR_Grid_Select" or something like
that.

2. Also in your <asp:ImageButton ....> tag, add the attribute
CommandName="Select"

3. Create your public sub called MR_Grid_Select(object sender,
EventArgs e)

4. Inside this function you can call get the attribute of the
DataGrid. me.MR_Grid.SelectedItem and this is the actual row you just
clicked on.

5. Now you can do what stephano said - basically
Dim myGrid as DataGrid =
me.MR_Grid.SelectedItem.Cells(9).FindControl("FVDG rid")

If mypanel.Visible = False Then
Mypanel.Visible = true
Else
Mypanel.Visible = false
End if

(If you only have one control in the column this will work too
me.MR_Grid.SelectedItem.Cells(9).Controls[0]... )

Forgive me, I'm no expert on VB.NET, so if syntax is wrong, sorry.

Hope this Helps.

-Danny

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview - is individual cell click event possible? K B ASP .Net 1 03-08-2007 09:03 AM
Individual cell color using JTable jpcaballerost@gmail.com Java 2 03-28-2006 02:03 PM
OnButtonClick make an individual cell visible/invisible? Roy ASP .Net 0 02-11-2005 02:27 PM
Changing individual table cell or row borders with CSS news frontiernet.net HTML 6 12-05-2003 03:46 AM
Give individual cell's a border? Harry Javascript 1 10-23-2003 04:03 PM



Advertisments