ONE cell DataGrid: should be easy(i think)

eramgarden

Contributor
Joined
Mar 8, 2004
Messages
579
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:
Code:
<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>
 
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??
 
Quick solution

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

Visual Basic:
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.
 
I tried your code and this:

Code:
 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?
 
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.
 
I have that code right after databinding to the datagrid..

but let me play around with it more. Will post again.

Thanks for all your help.
 
Back
Top