Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic <DIV> tag??? 2

Status
Not open for further replies.

jbenson001

Programmer
Jan 7, 2004
8,172
US
Hello all,

I am creating a form by adding controls dynamically. One of my controls is a DataGrid which has about 20 rows. In the past when not creating the form dynamically, I put the grid inside of a <DIV> tag so that I can have scroll bars to appear. I know the <DIV> tag is HTML, but is there anyway to add it at run time, around my grid, or am I way off here? Thanks for any help and suggestions.

Jim
 
You could always add the div tag at design time (and place the datagrid in it) then when needed add the attributes to add the scrollbars i.e. so it always exists but only becomes visible if you want it to.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
The problem is the whole usercontrol is built dynamically. The DIV can appear anwhere on the control
 
In that case I guess you could add it at runtime but you would have to do it in a sensible order. e.g.

1) Add the DIV tag
2) Add a copy of the DataGrid control to the div
3) Remove the original copy of the DataGrid

I do something similar using to use Inheritance so each of my pages inherits from a page base class. The same kind of principle is applied in that page base i.e.

1) Create a new form
2) Add all of the controls from the original form to the new form
3) Add all of my controls that I want to appear on each page
4) Remove all the original controls

I hope you understand what I mean as it's getting a bit late here and I'm not sure if I'm making sense!


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks for the response. I will keep it in mind. I am currently looking into using the HTMLTextWriter. Maybe this will be the way to go.
 
I don't see why you have to use a htmltextwriter. You could dynamically create a div and add your datagrid with:
Code:
System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");

div.Controls.Add(Your datagrid control);

You could also you a panel, but it seems that a panel only generates a div for IE and for anyother browser, it generates a table.
 
Thank you so much for the help! The examples I saw didn't show what you did.

I used this (using VB)
Code:
        Dim mydiv As System.Web.UI.HtmlControls.HtmlGenericControl
        mydiv = New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")

        Me.Controls.Add(mydiv)

I can't tell you how happy I am for your help. Thank you so much again!!!!


Jim
 
I just realized on problem however. By adding this code I get <DIV></DIV>

What I need is this

<DIV>
a datagrid here
</DIV>

Any Ideas????
 
Nevermind, sorry, I figured it out. Just added the controls I wanted to the collection of the div.
 
I completely miss you showing me the adding of the DG to the div. I guess I was to quick in my reading

THANKS!!!!!!
 
1) Add the DIV tag
2) Add a copy of the DataGrid control to the div
3) Remove the original copy of the DataGrid
That's what I was trying to explain with my above quote (I told you I wasn't making much sense! Guess I should have included an exmple).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
if i understood u correctly this may also work:
<DIV runat="server" id="TheDiv">


in code behind file:
Protected WithEvents TheDiv as HtmlGenericControl


if u want a scroll to appear:
TheDiv.Attributes.Add("style","overflow:auto")

Known is handfull, Unknown is worldfull
 
vbkris - That's what I suggested in my first post, but the poster explained that it wasn't possible.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ah (too enthusiastic)...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top