Using .Net1.1, I experienced a problem on how I could change the header text of a datagrid. Normally, you can set it like this (using the DataGridTableStyle):
DataSet ds = query("Select field_name from table");
datagrid.DataSource = ds.Tables[0];
//and NAME will be displayed as the datagrid's headertext.
DataGridTableStyle style = new DataGridTableStyle();
DataGridColumnStyle colStyle = new DataGridTextBoxColumn();
colStyle.HeaderText = "NAME";
colStyle.MappingName = "field_name";
style.GridColumnStyles.Add(colStyle);
datagrid.TableStyles.Add(style);
//Unfortunately it's not working.
//An alternative is to rename the column in the sql query:
DataSet ds = query("Select field_name AS NEW_FIELD_NAME from table");
datagrid.DataSource = ds.Tables[0];
Hi your code works fine except for one change in the code.
ReplyDeleteAdd style.MappingName="table name";
This is working!
Hi, yes your right forgot to paste that part.
ReplyDeleteAgain this part is very important:
style.MappingName="table name";
Thanks :-D
Post a Comment