473,378 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Gridview ItemStyle-Width Problem

Hi friends,

I have set a fixed width to my grid view.Now the next thing which I would want to do is set fixed width for all the columns in my grid view.I have tried all the below options but none of them work.Would be great if this gets solved.

1) Set the ItemStyle-Width of all BoundFields to 100px

Example:
Expand|Select|Wrap|Line Numbers
  1. <asp:BoundField DataField="Customer_Name" HeaderText="Customer" SortExpression="Customer_Name" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100px"/>
2) Define the column width in the RowDataBound event
Expand|Select|Wrap|Line Numbers
  1. protected void RPMData_RowDataBound(object sender, GridViewRowEventArgs e)
  2.         {
  3.             if (e.Row.RowType == DataControlRowType.DataRow)
  4.             {
  5.  
  6.  
  7.                 RPMData.Columns[0].ItemStyle.Width = 150;
  8.                 RPMData.Columns[1].ItemStyle.Width = 150;
  9.                 RPMData.Columns[2].ItemStyle.Width = 150;
  10.                 RPMData.Columns[3].ItemStyle.Width = 150;
  11.                 RPMData.Columns[4].ItemStyle.Width = 150;
  12.                 RPMData.Columns[5].ItemStyle.Width = 150;
  13.                 RPMData.Columns[6].ItemStyle.Width = 150;
  14.                 RPMData.Columns[7].ItemStyle.Width = 150;
  15.                 RPMData.Columns[8].ItemStyle.Width = 150;
  16.                 RPMData.Columns[9].ItemStyle.Width = 150;
  17.  
  18.  
  19.             }
  20.         }
3. Define the css and call the css in the RowDataBound Event

Source code:-

Expand|Select|Wrap|Line Numbers
  1. <style type="text/css">
  2.         .columnwidth
  3.         {
  4.             width: 150px;
  5.         }
  6.   </style>
Codebehind:-
Expand|Select|Wrap|Line Numbers
  1. protected void RPMData_RowDataBound(object sender, GridViewRowEventArgs e)
  2.     {
  3.         if (e.Row.RowType == DataControlRowType.DataRow)
  4.         {
  5.             for (int i = 0; i > e.Row.Cells.Count; i++)
  6.             {
  7.                 e.Row.Cells[i].CssClass = "columnwidth";
  8.             }
  9.         }
  10.     }
Dec 28 '16 #1
0 2738

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: kieran | last post by:
Hi, I was using the datagrid and am now starting to use the gridview in asp.net 2.0. I used to use the first below sub for when i would mouseover a row - this highlighted the row but did not...
1
by: coynej60 | last post by:
I have a GridView that is bound to a SqlDataSource that uses Stored Procedures for its Select, Insert, Update and Delete Commands. The Gridview only contains one visible column (PK Identity column...
1
by: kuangzhang | last post by:
Dear MS Gurus, I have read many posts on the Gridview pagerstyle problem but have yet to see a fix or an work around. Following is what I am experiencing: in the Aspx Page I have this <PagerStyle...
6
by: Greg | last post by:
Hello, I have a GridView bound to a custom object. I set the DataKeyNames property along with the column DataField properties at design time, and bind the GridView to my object at run-time. In...
8
by: =?Utf-8?B?TWlrZSBSYW5k?= | last post by:
I am trying to get a list of files from a specified directory using the System.IO namespace classes, and then use that list as the datasource for a GridView. I have been able to do this...
0
by: aj123 | last post by:
I have Table News NewsID, int NewsHeadLint, varcahr(200) OrderNews, int I gridView Display as following query Select ID,NewsHeadLine from News order By OrderNews DESC ---- <asp:GridView...
1
by: l3d007 | last post by:
I used this example straight from msdn in a gridview that already sorts based on each column. For some reason I cannot get it to sort based on two sorting expressions.Is there some property of the...
1
by: suganya | last post by:
I have displayed the data from the DB to the GridView made a column in the GridView as HyperLink allowed paging by setting the Allow Paging Property to "True". By clicking on the page no link I have...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
0
by: vinothrao84 | last post by:
Hi, i have the below gridview code in my asp.net c# page. Problem is i having an error saying that "A field or property with the name 'ProfileID, Image' was not found on the selected data...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.