views:

180

answers:

2

Is there a way for expanding the width of a TD in the table based on the width of the next TD.

The asp:Panel is going to be hidden or displayed based on some condition in the code behind.

I'm thinking it's some CSS thing that would help me fix this, but unable to put a finger on it. Help!!

Here's the HTML Markup:

    <tr>
 <td class="content_body" style="width: 294px">
  This is some long text needs to be dynamically wrapped...............................................................

 </td>
 <td>
 <asp:Panel ID="Panel1" runat="server">
  This is going to be hidden based on some condition in the Code behind
 </asp:Panel>
 </td>
</tr>
A: 

With jQuery, you could apply an id to the top td in the two columns and then do something like:

$('#tda').width(($('#tdb').width() > 200) ? 10 : 100)

This sets the width of td with id tda to 10 if td with id b is greater than 200 else it will set it to 100.

grenade
Yea this is probably the best way to do this. You may want to check the width then add a class to it (you should use classes because you may have more then one), then in your css define the width rules. This way the process is completely dynamic instead of manually adding the classes to the td's that need them.
Chad
Hey there. Would there be a CSS/Javascript based answer to this one. I don't have jQuery on this application, and it would require going through a lot of red tape to get that, unfortunately.
Vivek
jQuery is just javascript. If you go down the route of not including the jQuery script then you're gonna have to deal with browser compatibility, etc. I'm sure it's possible but writing something that works without jQuery is probably not a one liner...
grenade
+1  A: 

One thing to try would be to leave the width off of the TD that needs to expand/shrink based on the other TDs. Without a width, a TD will by default take up any available space, so if the other TDs in the row all have a width specified, the one without a width will take up the rest of the space. If there are 2 such TDs, the space will be distributed between them.

cdeszaq
Wow! I'm not sure how I missed playing with that option. Thanks a lot!!
Vivek
It can occasionally give some funny results if you don't have a really strong control/understanding over the elements and styles around the table, but otherwise, it is a nice, clean way of having expanding content.
cdeszaq