473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

OnButtonClick make an individual cell visible/invisible?

Roy
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

Nov 19 '05 #1
8 3962
Roy
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!

Nov 19 '05 #2
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" <ro**********@gmail.com> ha scritto nel messaggio
news:11**********************@z14g2000cwz.googlegr 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!

Nov 19 '05 #3
Roy
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?

Nov 19 '05 #4
Roy
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.

Nov 19 '05 #5
Roy
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.... ;)

Nov 19 '05 #6
Roy
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?

Nov 19 '05 #7
Roy
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?

Nov 19 '05 #8
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 <asp:DataGrid 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

Nov 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ronny Sigo | last post by:
Hello all, Could anybody help me referencing individual cells in excel? I don't know what I do wrong here (but I'm not familiar with excel vba) (Microsoft Excel 10.0 Object library is referenced)...
3
by: Susan Bricker | last post by:
Greetings. I have three forms that are open at the same time. They are related and cascading. The first form (frmEventAdd) is the anchor. Each event can have many Trials. The second form is...
4
by: Miguel Dias Moura | last post by:
Hello, i have 5 panels in an ASP.net / VB page. The panel 1 is visible the other 4 are NOT visible. I also have 5 images: image 1, image 2, ..., image5. When i click one of the images,...
0
by: Roy | last post by:
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...
6
by: Nick Stansbury | last post by:
Hi, I have a loop running on Page_PreRender that sets a number of controls to invisible based on a set of criteria. Before I do this however, I set all of the drop down lists to be visible with...
3
by: Mad Scientist Jr | last post by:
Can someone post a clear example of how to change the background color of an individual datagrid cell for a Windows desktop app? (preferably in vb.net) I found some code on how to do this when...
11
by: Jo | last post by:
Hi all, I have a gridview displaying a dataset and some buttons. When a certain cell of this datasetrow is empty, I want a button in that row to be visible, otherwise no button should be shown...
8
by: graphicsxp | last post by:
Hi, How can I get the value of a cell that belongs to a hidden column of gridview ? Here's how I normally access the value of a cell, but it doesn't work if the column is invisible: Code :...
0
by: simon | last post by:
hello, I was hoping someone could help me with an issue (using vb & .net 2.0) I have a datagrid and the first column shown i have an asp:textbox that i basically want to "group by" an ID and only...
2
by: chris | last post by:
I've created an ASP table which is dynamically populated and it has a hidden column at the end. The cell is marked as invisible but when I try and obtain the cell value in client side script...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.