0

I have a gridview which contains EditItemTemplate and ItemTemplate but gridview header not adjusting.How can i adjust my gridview header . Here is my gridview IMG

Here is my aspx.cs code :

<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>
6
  • How do you need it adjusted? Commented Jul 11, 2016 at 13:15
  • No it's not i want User_ID move left blow numbers like id etc,and same for all header like Name blow name but header move to the right i want to adjust it Commented Jul 11, 2016 at 13:19
  • I'm sorry, I don't understand what you are saying. Maybe try creating an image with how you would like it to look. I'm guessing that a GridView.HeaderStyle may help. Commented Jul 11, 2016 at 13:24
  • its th i check using inspectElement how can i adjust th in gridview.my simple question is i want to move left gridview th Commented Jul 11, 2016 at 13:26
  • I want this User_ID header blow numbers like 1,2,3... and in Name blow name comes like Hameed,Ali etc.and same for next Commented Jul 11, 2016 at 13:27

1 Answer 1

1

You can use the alignment properties of the header for each field:

<asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderStyle-VerticalAlign="Middle">
    ...
</asp:TemplateField>

If you need more control on the output, you can also create a HeaderTemplate:

<asp:TemplateField>
    <HeaderTemplate>
        <asp:Label runat="server" Text="..." />
        ...
    </HeaderTemplate>
    ...
</asp:TemplateField>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.