简体   繁体   English

GridView列宽

[英]GridView column width

I'm using VS 2010. I have a GridView with few template columns. 我使用的是VS2010。我有一个带有少量模板列的GridView。 I want the 2nd column to not be visible at all, but still to be existed so javascript will be able to see it's value. 我希望第二列根本不可见,但仍然存在,因此javascript将能够看到它的值。 Does someone knows how to set this width value? 有人知道如何设置此宽度值吗?

Thanks 谢谢

将HiddenField放在第一列中,然后将需要将其放在第二列中,而不是创建第二列。

The Problem: 问题:

Your problem originates from the fact that when you hide a data-bound GridView's column, its bounded value is no longer available and if you tried to access it you will get an empty string. 您的问题源于以下事实:当您隐藏数据绑定的GridView的列时,其绑定值不再可用,如果尝试访问它,您将得到一个空字符串。

The solution: 解决方案:

Enable 2 events in in your gridview: 在gridview中启用2个事件:

RowDataBound: In this event you can access the hidden cell value (before hiding it yet) RowDataBound:在这种情况下,您可以访问隐藏的单元格值(在将其隐藏之前)

protected void MyGridView_RowDataBound(Object sender, GridViewRowEventArgs)
{
   // Here you store the value
   this.sID = e.Row.Cells[1].Text;
}

RowCreated: In this event you hide the cell, write this in the event handler: RowCreated:在这种情况下,您将隐藏单元格,将其写入事件处理程序中:

protected void MyGridView_RowCreated(Object sender, GridViewRowEventArgs)
{
    // then you hide the cell (Only the cell not the column)
    e.Row.Cells[1].Visible = false;
}

In these codes, after we save the value we need in another variable/array whatever, we can easily hide the cell. 在这些代码中,在将所需的值保存到另一个变量/数组后,我们可以轻松地隐藏单元格。 You can put that value in a hidden input to enable accessing the value from javascript. 您可以将该值放在隐藏的输入中,以允许从javascript访问该值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM