当前位置:编程学习 > C#/ASP.NET >>

动态生成的girdview的列名怎么添加呀?

我现在自动生成的列名是我数据表中的字段.我现在想让他成为所对应的汉字. --------------------编程问答-------------------- 沙发,帮忙顶 --------------------编程问答-------------------- select name as 名称 from table试下 --------------------编程问答-------------------- 楼上的说清楚点,是什么意思,得到的怎么填充到girdview --------------------编程问答-------------------- 将自动生成列设置为假
参考一下
<div align="center">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDeleting="GridView1_RowDeleting" OnRowCommand="GridView1_RowCommand" DataKeyNames="NodeId" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating">
          <Columns>
            <asp:BoundField ItemStyle-Width="100" ControlStyle-Width="93" DataField="Url" HeaderText="Url" />
            <asp:BoundField ItemStyle-Width="100" ControlStyle-Width="93" DataField="NodeId" HeaderText="NodeId" />
            <asp:BoundField ItemStyle-Width="100" ControlStyle-Width="93" DataField="NodeName" HeaderText="NodeName" />
            <asp:TemplateField ItemStyle-Width="100" ControlStyle-Width="93" HeaderText="ParentId">
              <EditItemTemplate>
                <asp:TextBox ID="ParentId" runat="server" Text=<%# Eval("ParentId") %>>
                </asp:TextBox>
              </EditItemTemplate>
            </asp:TemplateField>
            <asp:ButtonField ItemStyle-Width="60" ControlStyle-Width="53" ButtonType="Button" CommandName="Hello" DataTextField="NodeId" HeaderText="NodeId"/>
            <asp:ButtonField ItemStyle-Width="60" ControlStyle-Width="53" ButtonType="Link" HeaderText="Delete" Text="Delete" CommandName="Delete"/>//此处不能使用Button,否则客户端脚本导致服务器Button事件无效
            <asp:TemplateField ItemStyle-Width="60" ControlStyle-Width="53" HeaderText="Delete">
              <ItemTemplate>
                <asp:Button ID="Delete" runat="server" CommandName="Delete" Text="Delete"/>
              </ItemTemplate>
            </asp:TemplateField>
            <asp:ButtonField ItemStyle-Width="60" ControlStyle-Width="53" ButtonType="Button" HeaderText="Edit" Text="Edit" CommandName="Edit"/>
            <asp:ButtonField ItemStyle-Width="60" ControlStyle-Width="53" ButtonType="Button" HeaderText="Update" Text="Update" CommandName="Update"/>
            <asp:ButtonField ItemStyle-Width="60" ControlStyle-Width="53" ButtonType="Button" HeaderText="Cancel" Text="Cancel" CommandName="Cancel"/>
          </Columns>
        </asp:GridView>
</div> --------------------编程问答-------------------- SELECT empName AS 职工姓名,empAge AS 职工年龄,empDept AS 职工部门 
FROM EmpInfo 
WHERE .....

GridView.AutoGenerateColumns = true; --------------------编程问答-------------------- 已经解决,但是还出现新问题,就是girdview控件自动生成的列怎么设置为固定列宽呀 
我的总列宽是固定的,每增加一项,总列宽不变,分列宽变窄了 
--------------------编程问答-------------------- 把girdView的width属性去掉 --------------------编程问答-------------------- 如果要避免GridView单元格内换行
可以在GridView的RowDataBound事件中加入如下处理:
foreach(TableCell cell in e.Row.Cells)
{
    cell.Text = "<nobr>" + cell.Text + "</nobr>";
} --------------------编程问答-------------------- 设置列属性 ItemStyle中的Wrap=false --------------------编程问答-------------------- 楼主经常不结贴吧? --------------------编程问答-------------------- 可以在GridView的RowDataBound事件中加入如下处理:
foreach(TableCell cell in e.Row.Cells)
{
    cell.Text = "<nobr>" + cell.Text + "</nobr>";
}
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,