Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m using Gridview inside of User control..so I have bind datatable values.

My Datatable column name is "ProjectGroupName" but I want to show my column header is "Project Group Name"...

plz suggest any idea..thanks

What I have tried:

objDatatable.Columns["ProjectGroupName"].ColumnName = "Project Group Name;

user control form:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GridViewUserControl.ascx.cs" Inherits="DailyUpdateWebServer.Control.GridViewUserControl" %>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <asp:GridView runat="server" ID="grdUserControl" OnSorting="grdUserControl_Sorting" AllowSorting="true" AutoGenerateColumns="true" CssClass="table table-striped table-bordered table-hover">
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

C#
public partial class GridViewUserControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
       
        }
       
        public DataTable DataSource
        {
            set
            {
              
                grdUserControl.DataSource = value;
                grdUserControl.DataBind();                
            }
        }
}


Class:
public class TaskView
    {
      
        public string ProjectGroupName { get; set; }
        public string ProjectName { get; set; }
       
}


aspx.cs:
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                TaskView obj = new TaskView();
                obj.GetTask();

                GridViewUserControl.DataSource = obj.GetTask(); // passing datatable
                GridViewUserControl.DataBind();
            }
        }
Posted
Updated 16-Feb-18 12:03pm
v3
Comments
Karthik_Mahalingam 16-Feb-18 2:19am    
show the gridview markup code.
venkatesh (chennai) 16-Feb-18 2:28am    
added code ji
Karthik_Mahalingam 16-Feb-18 5:03am    
value is datatable?
Laiju k 16-Feb-18 6:34am    
no Bound field or Template field?

1 solution

You could add template fields to your gridview and set the header text like this. (This goes inbetween your
<asp:GridView>
tags.

<asp:templatefield headertext="Project Group Name">
            <itemtemplate>
              <asp:label id="ProjectGroupNameLabel"
                Text= '<%# Eval("ProjectGroupName") %>'
                runat="server"/> 
            </itemtemplate>
          </asp:templatefield>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900