You must Sign In to post a response.
  • Category: ASP.NET

    Need to show the header in runtime in gridview using asp.net

    in a gridview i show the data as below

    name mobile

    celv 88073********

    ram 8807 **326362


    my need is

    Details of Employee(this is gridview header i need it in run time)
    name mobile

    celv 88073********

    ram 8807 **326362
  • #762273
    Hi

    Hello

    Today you have asking more than questions people also reply to you . If your issue fixed means select as best answer otherwise if your issue not fixed means let me know.


    If you need Runtime Change your Gridview Header Means

    try this code-- > Client Side


    <div id="div1" style="overflow:auto; width:400px;height:150px;">
    <asp:GridView ID="GrdData1" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:BoundField DataField = "EMPID" HeaderText = "EMPID ID" />
    <asp:BoundField DataField = "EMPNAME" HeaderText = "EMPNAME" />

    <asp:TemplateField ItemStyle-Width = "30px" HeaderText = "EMPID">
    <ItemTemplate>
    <asp:LinkButton ID="lnkEditRecord" runat="server" Text = "Edit" OnClick="lnkEditRecord_Click"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </div>


    Server Side


    DataTable dt = new DataTable();
    dt.Columns.Add("EMPID");
    dt.Columns.Add("EMPNAME");
    DataRow dr;
    dr = dt.NewRow();
    dr[0] = 1001;
    dr[1] = "Jayakumar";
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr[0] = 1001;
    dr[1] = "Jayakumar";
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr[0] = 1001;
    dr[1] = "Jayakumar";
    dt.Rows.Add(dr);
    dr = dt.NewRow();
    dr[0] = 1001;
    dr[1] = "Jayakumar";
    dt.Rows.Add(dr);
    dr = dt.NewRow();
    dr[0] = 1001;
    dr[1] = "Jayakumar";
    dt.Rows.Add(dr);
    dr = dt.NewRow();
    dr[0] = 1001;
    dr[1] = "Jayakumar";
    dt.Rows.Add(dr);

    GrdData1.DataSource = dt;
    GrdData1.DataBind();
    GrdData1.HeaderRow.Cells[0].Text = "Employee ID";
    GrdData1.HeaderRow.Cells[1].Text = "Employee Name";

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762283
    Hello Selvi,

    You can refer the below links :

    http://www.dotnetfox.com/articles/programmatically-creating-gridview-header-row-in-Asp-Net-using-C-Sharp-1059.aspx

    http://www.codeproject.com/Questions/646751/Dynamically-change-gridview-header-text-on-menu-se

    http://www.codeproject.com/Articles/27824/Dynamic-Multiple-Row-Column-Grid-Header

    http://vinaysingh2507.blogspot.in/2012/07/add-custom-gridview-header-dynamically.html


    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762285

    Hi selvi,

    I assume that this is the format you are expecting


    Details of Employee
    Name Mobile
    Raj 2222222222
    Karthi 3333333333


    Details of Employee should be top of Header part and it should be merged with all the columns, if your expectation is like that then follow below sample.


    <asp:GridView ID="gv" runat="server" AutoGenerateColumns="false" OnDataBound = "gv_OnDataBound">
    <Columns>
    </Columns>
    </asp:GridView>


    this is gridview design, here I'm using OnDataBound event, this will help us to clear the above issue.

    and on server side wrote below lines of code.


    protected void gv_OnDataBound(object sender, EventArgs e)
    {
    GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);

    TableHeaderCell cell = new TableHeaderCell();
    cell.Text = "Details of Employee";
    cell.ColumnSpan = 4; // no of cells you want you just give that much count
    row.Controls.Add(cell);

    row.BackColor = ColorTranslator.FromHtml("#3AC0F2");
    gv.HeaderRow.Parent.Controls.AddAt(0, row);
    }


    Try, something like above to achieve your goal.

    Hope this will helpful to you...


    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762294
    hi kumar forum is for asking questions. according to their requirement they asking questions . like that only i ask questions i never comple any one to answer my questions. if they wish to answeer my questions. if it is correct means i put as a best answer ...

    and all of them thanks for your effort

  • #762311
    Hi Mr.Kumar and Nirav.

    I have seen you people asking every time to choose as best answer.

    Don't force any one to do so, if at all they get satisfied with answers they will choose as best answer else they wont.

    Hope you people understand and don't mind.

    Regards

    Sridhar Thota.

    Sridhar Thota.
    Editor: DNS Forum.

  • #762313
    Hello Sridhar,

    You are wrong. I never force people to choose my answer as best answer. You can check my thread responses if you have any doubts.

    Check the below link :

    http://www.dotnetspider.com/member/ndlalan143.aspx

    After visiting the below link if you feel like i am asking every time people to choose as best answer then tell me.

    I hope you don't mind.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762315
    Hello Sridhar,

    You are think wrong. I never force people to choose my answer as best answer. I feel my answer is correct so thats y i mention select as a best answer . I have no need to force people to choose my answer as best answer. In my level i check how to my answer valuable to others . some members automatically select as best answer i never force they i never no need force people put select as best answer .

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


Sign In to post your comments