Hi Angela,
Thank you for posting in the community!
Based on my understanding, you want to implement a scrollable datagrid in
WebForm, and your datagrid is create dynamicly.
===========================================
From your statement, I see that you already know that scrollable datagrid
control is complemented through included in the <div> html tag with
"overflow" html attribute.
To dynamicly add your div tag, I think you want to get all this done at
server side. Actually, <div> html tag can be made into a server control
through HtmlGenericControl class.
HtmlGenericControl can be used to represent an HTML server control tag not
directly represented by a .NET Framework class, such as <span>, <div>,
<body>, and <font>.
So you can do like this:
protected System.Web.UI.HtmlControls.HtmlForm Form1;
private void Button1_Click(object sender, System.EventArgs e)
{
DataGrid dg=new DataGrid();
SqlDataAdapter adapter=new SqlDataAdapter("select * from
jobs","server=localhost; database=pubs;uid=sa; pwd=");
DataSet ds=new DataSet();
adapter.Fill(ds);
dg.DataSource=ds;
dg.DataBind();
Form1.Controls.Add(dg);
System.Web.UI.HtmlControls.HtmlGenericControl divcontrol=new
HtmlGenericControl("div");
divcontrol.Style.Add("width", "300");
divcontrol.Style.Add("height", "400");
divcontrol.Style.Add("overflow", "scroll");
divcontrol.Controls.Add(dg);
Form1.Controls.Add(divcontrol);
}
In the sample code, I dynamicly add the datagrid control in button.click
event.
Also, I want to inform you that: <div>'s "overflow" attribute has 4 values:
visible, scroll, hidden, auto. I use "scroll" here to make scroll bars are
always added, even if the content does not exceed the dimensions of the
object.
For more details information, please refer to:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/ref
erence/properties/overflow.asp
=================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.