.NET4.0 I understand that this is a problem that was fixed in .NET 4.0+, however upd...">

Asp: Gridview & asp: Table-generated property border = "0" in> .NET4.0

I understand that this is a problem that was fixed in .NET 4.0+, however updating our infrastructure is not yet an option. SOON, but not yet. I am currently using .NET 3.5.

As I saw in many other posts, this is a very common problem. No one really says why this is a problem, so it seems that many answers do not seem to understand the real problem.

When using asp: Table control or asp: GridView, the generated label looks like this:

<asp:Table id="table1" border="0" runat="server"></asp:Table> 

Gridview is pretty much the same, but it includes the 'rules' attribute, which can be omitted by setting the Gridlines property to none. However, when setting up grid lines, no one needs the rule attribute, the border = "0" always remains.

Now the problem is : to test this code using the W3 validator, the border property MUST be set to border = "OR border =" 1. "This seems like a very simple fix, further research proves quite the opposite.

I tried changing the value to what the validator accepts:

t

 table1.Attributes.Add("border", "1"); // This generates <asp:Table id="table1" border="0" border="1" runat="server"></asp:Table> table1.Attributes.Add("border", null); // This generates <asp:Table id="table1" border="0" border="" runat="server"></asp:Table> table1.Attributes["border"] = "1"; // This generates <asp:Table id="table1" border="0" border="1" runat="server"></asp:Table> table1.Attributes["border"] = ""; // This generates <asp:Table id="table1" border="0" border="" runat="server"></asp:Table> table1.Attributes.Remove("border"); // This generates <asp:Table id="table1" border="0" runat="server"></asp:Table> 

None of them achieved the desired result. asp: The table always generates border = "0" and I cannot change the value.

Does anyone have any other ideas, and, again, upgrading the framework is not yet an option. In the near future we will upgrade, but not earlier than this version will be released.

Thank you very much

+4
source share
5 answers

I studied this problem for quite some time, and nothing that I read on the Internet could fix this problem, and even the recommended ideas of Framework 4.0 did not work, since my application was already intended for platform 4.0, but still, uninstall it "Border = 0" from the GridView control. However, I found that my Web.Config, although targeting Framework 4.0, also had controlRenderingCompatibilityVersion set to "3.5" in the Pages tag. By removing this option, it automatically gets rid of the Border attribute of the GridView control.

+3
source

The workaround is to do this by clicking on the GridView RowDataBound event, for example:

 protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e) { foreach (TableCell tc in e.Row.Cells) { tc.Attributes["style"] = "border: 1px solid #ccc"; } } 

Using the GridView, the declarative border attribute adds a row-style declaration that applies only to the table itself and not to individual cells.

Adding the border attribute programmatically does not use the inline style, but uses the HTML border property, which browsers apply to all borders within the table.

Another thing, if you use Eric Meyer reset, it splits the rendering of the table in the GridView. The solution to this particular problem is to remove all table elements from the reset rule. This can lead to the fact that the table itself will not be pleasant for you.

0
source

In the code behind the code added below, it will work.

 gridview1.Attributes.Remove("border"); 

or

 gridview1.GridLines = GridLines.None; 

Thanks,

0
source

in my case, working with a team project with many different parts of the design, the best solution so far has been to use jQuery to remove the attribute border from the table, this procedure is not spoiled by the way other components display in different areas of the web application and will allow you to pass a validation check for the HTML page.

  <script type="text/javascript">$('#TableID').removeAttr("border");</script> 

Of course, this is an "on page" solution. Hope this helps!

0
source

Just add GridLines="None" to the gridview. It will remove the border attribute.

Welcome.

0
source

Source: https://habr.com/ru/post/1485037/


All Articles