我想使用asp.net在gridview中设置控件的宽度吗? [英] I want to set width for control in gridview using asp.net?
本文介绍了我想使用asp.net在gridview中设置控件的宽度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个gridview控件,并且我在其中使用ASP:BoundFields字段.
我想设置asp:boundfields控件的宽度.
我已经尝试了很多Google可用的功能,但这似乎是我的帮助.
就像任何人都已经做过的那样,并且有相同的解决方案.
Hi,
I have a gridview control and i am using ASP:BoundFields fields within it.
I want to set width of asp:boundfields control.
I have tried lot of things available in google but it seems to be my help.
As anyone already did it and have solution for the same.
推荐答案
尝试一下.
<asp:BoundField DataField="RowNumber" HeaderText="SNo" >
<ItemStyle Width="500px" />
</asp:BoundField>
谢谢
Thanks
嗨
查看以下链接
link1 [
hi
check out the following links
link1[^]
or
try this code
private void loadDynamicGrid()
{
#region Code for preparing the DataTable
//Create an instance of DataTable
DataTable dt = new DataTable();
//Create an ID column for adding to the Datatable
DataColumn dcol = new DataColumn(ID ,typeof(System.Int32));
dcol.AutoIncrement = true;
dt.Columns.Add(dcol);
//Create an ID column for adding to the Datatable
dcol = new DataColumn(NAME, typeof(System.String));
dt.Columns.Add(dcol);
//Now add data for dynamic columns
//As the first column is auto-increment, we do not have to add any thing.
//Let''s add some data to the second column.
for (int nIndex = 0; nIndex < 10; nIndex++)
{
//Create a new row
DataRow drow = dt.NewRow();
//Initialize the row data.
drow[NAME] = "Row-" + Convert.ToString((nIndex + 1));
//Add the row to the datatable.
dt.Rows.Add(drow);
}
#endregion
//Iterate through the columns of the datatable to set the data bound field dynamically.
foreach (DataColumn col in dt.Columns)
{
//Declare the bound field and allocate memory for the bound field.
BoundField bfield = new BoundField();
//Initalize the DataField value.
bfield.DataField = col.ColumnName;
//Initialize the HeaderText field value.
bfield.HeaderText = col.ColumnName;
//Add the newly created bound field to the GridView.
GrdDynamic.Columns.Add(bfield);
}
//Initialize the DataSource
GrdDynamic.DataSource = dt;
//Bind the datatable with the GridView.
GrdDynamic.DataBind();
}
这篇关于我想使用asp.net在gridview中设置控件的宽度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文