datagrid 里 headtext = "中文名" 就行了
解决方案 »
- 对于网络不文档的winForm程序控制
- DataGridView单元格操作的问题
- 初学者提问,谁能给出GridView控件里批量操作的代码吗?没分,希望有人能解答,网上找的代码都不对
- json
- 100分:关于c#设置注册表某键的权限
- 怎么样用正则表达式进行字符串的替换?
- 如何通过选择A页面的下拉菜单实现B页面datagrid的显示和跳转?
- 注册时用到的机器码怎么用c#得到?
- datagrid绑定一张表时,比如有两个字段,学院下拉列表和系下拉列表,能否实现在选择一个学院后,系的下拉列表中只显示和学院相关的系
- 简单问题,高手请进!
- C# 中如何获得鼠标在界面中划出的一片区域的4个点的 坐标?
- dataset里同一个table的两个字段的值相减?
另一种是在dataGrid,新建立一个DataGridTableStyle
谢谢
{
/* Create a new DataGridTableStyle and set
its MappingName to the TableName of a DataTable. */
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "Customers"; /* Add a GridColumnStyle and set its MappingName
to the name of a DataColumn in the DataTable.
Set the HeaderText and Width properties. */
DataGridColumnStyle boolCol = new DataGridBoolColumn();
boolCol.MappingName = "Current";
boolCol.HeaderText = "IsCurrent Customer";
boolCol.Width = 150;
ts1.GridColumnStyles.Add(boolCol);
// Add a second column style.
DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "custName";
TextCol.HeaderText = "Customer Name";
TextCol.Width = 250;
ts1.GridColumnStyles.Add(TextCol);
// Create the second table style with columns.
DataGridTableStyle ts2 = new DataGridTableStyle();
ts2.MappingName = "Orders";
// Change the colors.
ts2.ForeColor = Color.Yellow;
ts2.AlternatingBackColor = Color.Blue;
ts2.BackColor = Color.Blue;
// Create new DataGridColumnStyle objects.
DataGridColumnStyle cOrderDate =
new DataGridTextBoxColumn();
cOrderDate.MappingName = "OrderDate";
cOrderDate.HeaderText = "Order Date";
cOrderDate.Width = 100;
ts2.GridColumnStyles.Add(cOrderDate); PropertyDescriptorCollection pcol = this.BindingContext
[myDataSet, "Customers.custToOrders"].GetItemProperties();
DataGridColumnStyle csOrderAmount =
new DataGridTextBoxColumn(pcol["OrderAmount"], "c", true);
csOrderAmount.MappingName = "OrderAmount";
csOrderAmount.HeaderText = "Total";
csOrderAmount.Width = 100;
ts2.GridColumnStyles.Add(csOrderAmount); // Add the DataGridTableStyle objects to the collection.
myDataGrid.TableStyles.Add(ts1);
myDataGrid.TableStyles.Add(ts2);
}
try
{
mycnn= new SqlConnection("Server=ZHURONGj;Database=学生管理数据库;User id=dazhu2;Password=32012;trusted_connection=false");
mycnn.Open();
if(mycnn.State==System.Data.ConnectionState.Open)
{
MessageBox.Show(" 数据库连接成功!","提示",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Information);
string s="select * from 学生情况表;select * from 籍贯";
mydp=new SqlDataAdapter(s,mycnn);
//set up table mappings
mydp.TableMappings.Add("table","info");
mydp.TableMappings.Add("table1","jg"); //set up column mapping
mydp.TableMappings["table"].ColumnMappings.Add("name","姓名"); //create dataset
mydateset=new DataSet();
mydp.Fill(mydateset,"table");
//bind database to datagrid
this.dataGrid1.SetDataBinding(mydateset,"info");
this.dataGrid2.SetDataBinding(mydateset,"jg"); //ADD event of dataset
mydateset.Tables[0].RowChanged+=new DataRowChangeEventHandler(mydo);
this.button2.Enabled=true;
}
}
catch(Exception my)
{
MessageBox.Show(my.Message.ToString(),"提示",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error);
}
<asp:BoundColumn DataField="数据库字段" HeaderText="你要显示的中文名称">
<ItemStyle Wrap="False" Width="20%"></ItemStyle>
</asp:BoundColumn>
一种是在数据源处理,即把查处的数据字段取别名,换成你要的字段名 select 数据库字段 as 你定义名称
一种是在dataGrid中处理。可加绑定列,模板列等等。<asp:BoundColumn DataField="数据库字段" HeaderText="显示字段" >
有标题这一项
2、去掉“在运行时自动生成列”选项;
3、把可用列中的“所有字段”选中,加为“可用字段”;
4、为每个字段的页眉文本写上中文名就行了。