I develop a Webpart, which should be deployed in other SP-Farms.
The Webpart contains a DataTable.
I deployed the solution and the DataTable appears in the right side of the Website.
I'm using a gridView and have some style-components like margin-right: 50px.

I understand that the Table appears in the right side of the Website, but is there a opportunity to get the Table only into the Webpart?

at the momemt

should be

I use a GridView and want to do the css here with the cssstylecollection. but it doesnt really work?


  • Hi Grekko, I'm not sure what you are asking, to clarify could you possible post an image of your issue? I gave you 5 points for your post which should give you enough to post the image. – Hugh Wood Nov 28 '12 at 15:15
  • The DataTable should be in the WebPart no matter how big the size of the Screen or the browser is. – grekko Nov 28 '12 at 15:34
  • Hi Grekko, this looks like a CSS issue definitely. Are you able to go to jsfiddle.net and paste an example of the offending html there from the issue, and we can have a play and make it fit? – Hugh Wood Nov 28 '12 at 15:50

hi can you please post your css, its all todo with the position element weather it relative or absolute, also set the display to block. So the two element should have the following css:



add this class to 12hive:

for me I have a master css class that add other css classes too it like for webparts using import directive.

@import url (/_Layouts/1033/styles/customfolder/webparts/thisIsTheCssFile.css);

but you can do the following:

protected override void CreateChildControls()

How to use custom CSS with my Sharepoint WebPart?

within the code where your creating your object you need to assign the cssclass class name to the control you want changing, so as an example:

protected override void CreateChildControls()
   TreeView tv = new TreeView();
   tv.CssClass = "treeviewcss";

   DataTable dt = new DataTable();
   dt.CssClass = "datatable";

hope it helps :)

  • the float:left!important and Display:inline-block!important were very helpful. thanks. – grekko Dec 5 '12 at 14:22
  • your welcome! glad to be of some help – Ali Jafer Dec 5 '12 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.