Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a datagrid with ONE cell. In that ONE cell, I have a table with rows and columns...

 

I want, Depending on "MODE", hide the value bound to txtAdd18 ...

 

I tried: e.Item.Cells(0).Visible = False But this hides the WHOLE cell since i ONLY HAVE ONE CELL...

 

I also tried: e.Item.Cells(0).FindControl("txtAdd18").Visible = False But got an error that object is not set...

 

Anyway to do this without creating a new DataGrid for different Modes??

 

Code looks something like this:

<asp:datagrid id=... [b]OnItemDataBound="dg_hide"[/b]> 
<Columns> 
  <asp:TemplateColumn> 
    <ItemTemplate> 
      <table> 
        <tr> 
         <td>                                    <%# Container.DataItem("Other9") %> 
     </td> 
        </tr> 
        <tr> 
         <td>                                    <%# Container.DataItem("Other10") %> 
     </td> 
        </tr> 
       </table> 
    </ItemTemplate> 
    <EditItemTemplate> 
       <tr><td>[b]<asp:Textbox id="txtAdd18"... />[/b]</td></tr> 
       <tr><td>...</td></tr> 

Posted

txtAdd18.Visible = false won't work ?

being invisible won't render it by the way... (server-side) so no events will occur.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

NO, that wont work. This is inside a DATAGRID...

 

There has to be a way to do this:

 

when you only have ONE CELL, with rows/columns of data in it...how do you access the values in that ONE cell??

Posted

Quick solution

 

TextBox txt = (TextBox)dgPosts.Items[0].Cells[0].FindControl("txtAdd18");
txt.Visible = false;

 

Dim txt as TextBox = CType(dgPosts.Items[0].Cells[0].FindControl("txtAdd18"), TextBox)
txt.Visible = False

 

I didn't know in which language you were programming.

But try this. it's worth a try.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

I tried your code and this:

 

Dim txtP As TextBox = CType(dgContactAddInfoBottom.Items(0).FindControl("txtPhone"), TextBox)
               Dim txtH As TextBox = CType(dgContactAddInfoBottom.Items(0).FindControl("txtHours"), TextBox)
               txtP.Visible = False
               txtH.Visible = False

 

But when it gets to txtP, i get error msg that object is not set. Any ideas?

Posted

Maybe your control didn't exists.

 

My recommendation... look into Controls property the verify that it's in this line. take a look at other lines too (maybe have more than one even If only one is showed).

 

But really look into Controls collection in debug mode. Maybe your control isn't created yet.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...