Link to home
Start Free TrialLog in
Avatar of Saroj13
Saroj13

asked on

Urgent: Gridview header format asp.net, c#?

Hi,

gridview.doc
I need to create a gridview which header looks similar to the picture shown in the attachment. Also, ID, Title, Eng, SP, Publish Date, Delete Date are the sortable columns.

Please let me know how to achive this type of header?

Thanks
Avatar of Mrunal
Mrunal
Flag of India image

ASKER CERTIFIED SOLUTION
Avatar of Manoj Patil
Manoj Patil
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Saroj13
Saroj13

ASKER

Thanks.
I tried the above solutions and able to display.
ISSUE. Issue is for Publish Date column. I want to display Publish Date in two rows. Publish and Language comes in one line. Date comes in same line with Eng and Sp. Publish Date should be sortable column.

Current Format
                         Language  
ID      Title        Eng   SP              Publish Date

Required format
                         Language         Publish
ID      Title       Eng    Sp            Date


 <asp:GridView ID="gvScripts" runat="server" Width="100%" Height="100%" AutoGenerateColumns="False" AllowSorting="True" DataKeyNames="Script_ID"  
DataSourceID="scriptsSource"   style="position: relative; border: solid 1px #cccccc;" OnRowCreated="gvScripts_RowCreated" OnRowDataBound="gvScripts_RowDataBound"  GridLines="Both" BorderWidth="0">  
    <Columns>
          <asp:TemplateField HeaderText="ID" SortExpression="Script_ID" ItemStyle-BorderWidth="1px" ItemStyle-BorderColor="#cccccc" HeaderStyle-CssClass="GridHeaderStyle" >
                <ItemTemplate >
                    <%#  Eval("Script_ID")%>
                </ItemTemplate>
            </asp:TemplateField>
             <asp:TemplateField HeaderText="Title" SortExpression="ScriptTitle"  >
                <ItemTemplate>       
               <%# Eval("ScriptTitle")%>

                </ItemTemplate> 
                  <ItemStyle Width="260px" VerticalAlign="Top" Wrap="true" />
             </asp:TemplateField >
 <asp:TemplateField HeaderText="Eng" SortExpression="EnglishText" >
                                                   <ItemTemplate>
                                                      <%# GetImageNameForEnglishText(Container.DataItem) %>                                                   
                                                 </ItemTemplate>
  </asp:TemplateField>
          <asp:TemplateField HeaderText="Sp" SortExpression="SpanishText">                                               
 <ItemTemplate>                           
                                                <asp:Label  runat="server"><p style="text-align:center;">
<%# GetImageNameForSpanishText(Container.DataItem)%></p></asp:Label>
                                                  
                                                    </ItemTemplate>
                                                    <ItemStyle Width="35px" HorizontalAlign="Center" VerticalAlign="Top"/>
                                                         </asp:TemplateField>
<asp:TemplateField HeaderText="Publish Date" ItemStyle SortExpression="Publish Date" >
<ItemTemplate> <%# Eval("isNewPending")%> </ItemTemplate>
</asp:TemplateField>

 </Columns>
                                        </asp:GridView>



c#
 protected void gvScripts_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {

            GridView HeaderGrid = (GridView)sender;
            GridViewRow HeaderRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
            TableCell Cell_Header = new TableCell();

            Cell_Header = new TableCell();
            string hexColor = "#43816E";
            System.Drawing.Color color = System.Drawing.Color.FromName(hexColor);
            //    Cell_Header.Text = "Script_ID";
            Cell_Header.HorizontalAlign = HorizontalAlign.Center;
            Cell_Header.ColumnSpan = 1;
            Cell_Header.RowSpan = 1;
            Cell_Header.BorderColor = color;
            Cell_Header.Style["border-left"] = "1px solid #cccccc";

            HeaderRow.Cells.Add(Cell_Header);

            Cell_Header = new TableCell();
            //     Cell_Header.Text = "Title";
            Cell_Header.HorizontalAlign = HorizontalAlign.Center;
            Cell_Header.ColumnSpan = 1;
            Cell_Header.RowSpan = 1;
            Cell_Header.BorderColor = color;
            Cell_Header.Style["border-left"] = "solid 1pt #cccccc";

            HeaderRow.Cells.Add(Cell_Header);

           Cell_Header = new TableCell();
            Cell_Header.Text = "&nbsp;" + "Language";
            Cell_Header.HorizontalAlign = HorizontalAlign.Center;
            Cell_Header.ColumnSpan = 2;
            Cell_Header.Style["border-left"] = "solid 1px #cccccc";
			Cell_Header.Style["border-bottom"] = "solid 1px #cccccc";
            HeaderRow.Cells.Add(Cell_Header);

            gvScripts.Controls[0].Controls.AddAt(0, HeaderRow);
       }
    }

    protected void gvScripts_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.Header)
        {
        }

        foreach (DataControlField field in gvScripts.Columns)
        {
        }
		
		foreach (TableCell tc in e.Row.Cells)    {      tc.Attributes["style"] = "border-color: #cccccc";    }; 

    }

Open in new window