我有一个gridview,其中包含EditItemTemplate
和ItemTemplate
但gridview
标题未调整。我如何调整gridview
标题。
这是我的gridview
这是我的aspx.cs代码:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Enableviewstate="False" Width="1000px" CellPadding="2" ForeColor="#333333" AllowPaging="true" Height="400px" DataKeyNames="User_ID" onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
onrowupdated="GridView1_RowUpdated" onrowupdating="GridView1_RowUpdating" >
<Columns>
<asp:TemplateField AccessibleHeaderText="User_ID" HeaderText="User_ID">
<EditItemTemplate>
<asp:TextBox ID="TXT_ID" runat="server" Text='<%# Eval("User_ID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="txt_id" runat="server" Text='<%# Eval("User_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Name " HeaderText="Name">
<EditItemTemplate>
<asp:TextBox ID="TXT_NAME" runat="server" Text='<%# Eval("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="txtName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="User_Name" HeaderText="User_Name">
<EditItemTemplate>
<asp:TextBox ID="TXT_USERNAME" runat="server" Text='<%# Eval("User_Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="txt_username" runat="server" Text='<%# Eval("User_Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Email" HeaderText="Email">
<EditItemTemplate>
<asp:TextBox ID="TXT_EMAIL" runat="server" Text='<%# Eval("Email") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="txt_email" runat="server" Text='<%# Eval("Email") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Password" HeaderText="Password">
<EditItemTemplate>
<asp:TextBox ID="TXT_PASSWORD" runat="server" Text='<%# Eval("Password") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="txt_password" runat="server" Text='<%# Eval("Password") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Date" HeaderText="Date">
<EditItemTemplate>
<asp:TextBox ID="TXT_DATE" runat="server" Text='<%# Eval("Date") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="txt_Date" runat="server" Text='<%# Eval("Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<HeaderStyle HorizontalAlign="Left" CssClass="header" BackColor="#7961da"
Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
</asp:GridView>
</div>
</form>
答案 0 :(得分:1)
您可以为每个字段使用标题的对齐属性:
<asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderStyle-VerticalAlign="Middle">
...
</asp:TemplateField>
如果您需要对输出进行更多控制,还可以创建HeaderTemplate:
<asp:TemplateField>
<HeaderTemplate>
<asp:Label runat="server" Text="..." />
...
</HeaderTemplate>
...
</asp:TemplateField>