[英]Format GridView Auto Generated Columns
我正在尝试动态格式化gridview列的宽度,以便于在编辑和更新中使用。 是否可以定义多个列宽? 这是我用来创建gridview的代码...
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Create a new table.
DataTable taskTable = new DataTable("TaskList");
// Create the columns.
taskTable.Columns.Add("Id", typeof(int));
taskTable.Columns.Add("Description", typeof(string));
taskTable.Columns.Add("IsComplete", typeof(bool));
//Add data to the new table. - could fill the table from database query if desired
for (int i = 0; i < 1; i++)
{
DataRow tableRow = taskTable.NewRow();
//tableRow["Id"] = 0;
tableRow["Description"] = "";
tableRow["IsComplete"] = false;
taskTable.Rows.Add(tableRow);
}
//Persist the table in the Session object.
Session["TaskTable"] = taskTable;
//Bind data to the GridView control.
BindData();
}
}
是否可以发表这样的声明:
taskTable.Column.Add("Id", typeof(int), width="200px");???
首先,您必须将AutoSizeColumnsMode设置更改为fill,然后才能更改列的宽度。
dataGridView1.Columns[columnName].AutoSizeMode= DataGridViewAutoSizeColumnMode.None;
dataGridView1.Columns[columnName].Width = columnWidth;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.