Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Using Max-length for width of column i tried but it is snot working,
row-span is also not worked 

I want to change width of first column witch is dynamically generated from database using string builder sp.append


What I have tried:

foreach (DataColumn column in dt2.Columns)
                        {
                            sb.Append("<th width='20%' style = 'background-color: #e7e7e7;color:#000000'>");
                            sb.Append(column.ColumnName);
                            sb.Append("</th>");                            
                        }
                        sb.Append("</tr>");
                        foreach (DataRow row in dt2.Rows)
                        {
                            sb.Append("<tr>");
                            foreach (DataColumn column in dt2.Columns)
                            {
                                sb.Append("<td style='font-size:12px;line-height:26px;'>");
                                sb.Append(row[column]);
                                sb.Append("</td>");
                            }
                            sb.Append("</tr>");
                        }
Posted
Updated 24-Oct-17 20:58pm

DataTables, DataRows, and DataColumns do not have any width or height - they are not directly presented to the user and have no UI - the width and height only have any relevance for the presentation controls which display the data they contain.

In this case, you are using HTML tables to display your data, so you are (correctly) using the th width setting, but you have the format wrong: HTML th width Attribute[^] - the 20% needs to be in double quotes:
sb.Append("<th width=\"20%\" style = 'background-color:...
Or included in the CSS style:
sb.Append("<th style='width:20%;background-color:...
 
Share this answer
 
Quote:
I want to change width of first column witch is dynamically generated from database using string builder sp.append

C#
for (int i = 0; i < dt2.Columns.Count; i++)
            {
                string width = i == 0 ? "'50%'" : "'20%'"; // first column will be 50% and others 20%
                sb.Append("<th width=" + width+" style = 'background-color: #e7e7e7;color:#000000'>");
                sb.Append(dt2.Columns[i].ColumnName);
                sb.Append("</th>");
            }
 
Share this answer
 
Comments
Anuj Mehta 26-Oct-17 1:05am    
Same output, no change on my width,
it's not working, please give me any other suggestion .
Karthik_Mahalingam 26-Oct-17 1:13am    
show your full code.
wil try to replicate
Karthik_Mahalingam 26-Oct-17 4:57am    
why posting and deleting it.
Anuj Mehta 26-Oct-17 5:26am    
because value between <" "> is not displaying.
Karthik_Mahalingam 26-Oct-17 5:46am    
use pre tag

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900