Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4250080
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:28:53+00:00 2026-05-21T04:28:53+00:00

I have defined a nested grid view in the following way. <asp:GridView ID=GridView1 runat=server

  • 0

I have defined a nested grid view in the following way.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound" GridLines="None">
    <Columns>
        <asp:BoundField DataField="Date Of Transaction" HeaderText="Date Of Transaction"
            SortExpression="Date Of Transaction" />
        <asp:BoundField DataField="Invoice Number" HeaderText="Invoice Number" SortExpression="Invoice Number" />
        <asp:BoundField DataField="totalAmount" HeaderText="totalAmount" ReadOnly="True"
            SortExpression="totalAmount" />
        <asp:TemplateField>
            <ItemTemplate>
                <asp:GridView ID="gridView2" runat="server" HorizontalAlign="Left" ShowHeader="false" GridLines="None" OnRowDataBound="gridView2_RowDataBound">
                <Columns>
                <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100px">
                <ItemTemplate>
                <asp:Button ID="Btn1" runat="server" Text="Download" OnClick="Btn1_Click"/>
                </ItemTemplate>
                </asp:TemplateField>
                </Columns>
                </asp:GridView>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ComponentDBConnectionString %>"
    SelectCommand="SelectUserPreviousHistory" SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:Parameter DefaultValue="XYZZ" Name="userName" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

The screenshot of the output is here. As you can see i have a “Download” button in each row of the child gridview (i.e., gridView2) but I want the download button to be last column but .net is rendering it to be the first column.

How can I do it?

More over gridview2 datasource is arraylist. Here is the code

gridView2.DataSource = titlesArrayList;
gridView2.DataBind();

Please help me

Thanks in anticipation

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:28:54+00:00Added an answer on May 21, 2026 at 4:28 am

    Why don’t you simply add a Label before the Donwload-Button in the ItemTemplate? You could set the Label’s Text in RowDataBound(gridView2_DataBound).

    Edit: to show the header columns of the nested gridview in the header of the outer gridview, you could set ShowHeader="false" in the inner grid and use a HeaderTemplate with two labels for “Software Titles” and “Download here” and appropriate CSS-Styles to fit to the inner grid.

    Edit:

    Here is a working test-page. Pick the parts you didn’t understand:

    aspx:

        <asp:GridView ID="GrdTransaction" runat="server" OnRowDataBound="GrdTransaction_RowDataBound" AutoGenerateColumns="false">
            <Columns>
            <asp:BoundField DataField="DateOfTransaction" HeaderText="Date Of Transaction"
                SortExpression="DateOfTransaction" />
            <asp:TemplateField>
                <HeaderTemplate>
                    <table width="100%" cellspacing="0" cellpadding="0" border="0">
                        <tr>
                            <td><asp:Label ID="LblFileNameHeader" Text="File-Name" runat="server" /></td><td><asp:Label ID="LblDownloadHeader" Text="Download file" runat="server" /></td>
                        </tr>
                    </table>
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:GridView ID="GrdDocument" runat="server" ShowHeader="false" GridLines="None" AutoGenerateColumns="false"
                        OnRowCommand="GrdDocument_RowCommand" OnRowDataBound="GrdDocument_RowDataBound">
                        <Columns>
                        <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100px">
                            <ItemTemplate>
                                <asp:Label ID="LblFileName" Text='<%# Eval("Doc")%>' runat="server" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100px">
                            <ItemTemplate>
                                <asp:Button ID="BtnDownload" runat="server" CommandArgument='<%# Eval("Doc")%>' CommandName="Download" Text="Download" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </ItemTemplate>
            </asp:TemplateField>
            </Columns>
        </asp:GridView>
    

    Codebehind(converted from vb.net to c#):

    public class WebForm1 : System.Web.UI.Page
    {
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                this.GrdTransaction.DataSource = GetOuterGridSource();
                this.GrdTransaction.DataBind();
            }
        }
    
        private DataTable GetOuterGridSource()
        {
            DataTable tbl = new DataTable();
            tbl.Columns.Add(new DataColumn("ID", typeof(Int32)));
            tbl.Columns.Add(new DataColumn("DateOfTransaction", typeof(DateTime)));
            DataRow row = tbl.NewRow();
            row["ID"] = 1;
            row["DateOfTransaction"] = System.DateTime.Now;
            tbl.Rows.Add(row);
            row = tbl.NewRow();
            row["ID"] = 2;
            row["DateOfTransaction"] = System.DateTime.Now;
            tbl.Rows.Add(row);
            row = tbl.NewRow();
            row["ID"] = 2;
            row["DateOfTransaction"] = System.DateTime.Now;
            tbl.Rows.Add(row);
            return tbl;
        }
    
        private DataTable GetNestedGridSource()
        {
            DataTable tbl = new DataTable();
            tbl.Columns.Add(new DataColumn("ID", typeof(Int32)));
            tbl.Columns.Add(new DataColumn("Doc", typeof(string)));
            DataRow row = tbl.NewRow();
            row["ID"] = 1;
            row["Doc"] = "Smart Defrag";
            tbl.Rows.Add(row);
            row = tbl.NewRow();
            row["ID"] = 2;
            row["Doc"] = "Visio Viewer";
            tbl.Rows.Add(row);
            row = tbl.NewRow();
            row["ID"] = 2;
            row["Doc"] = "Rapid Typing";
            tbl.Rows.Add(row);
            return tbl;
        }
    
        protected void GrdTransaction_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow) {
                dynamic row = ((DataRowView)e.Row.DataItem).Row;
                dynamic GrdDocument = (GridView)e.Row.FindControl("GrdDocument");
                GrdDocument.DataSource = GetNestedGridSource();
                GrdDocument.DataBind();
                GrdDocument.RowCommand += GrdDocument_RowCommand;
            }
        }
    
        protected void GrdDocument_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow) {
                dynamic row = ((DataRowView)e.Row.DataItem).Row;
                dynamic LblFileName = (Label)e.Row.FindControl("LblFileName");
                LblFileName.Text = row("Doc").ToString;
            }
        }
    
        protected void GrdDocument_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Download") {
                dynamic docName = e.CommandArgument.ToString();
            }
        }
        public WebForm1()
        {
            Load += Page_Load;
        }
    }
    

    I have set the LblFileName’s Text poperty in GrdDocument_RowDataBound. That is redundant because i’ve always used eval on the aspx-page. I wanted to show both ways for the sake of completeness.

    This is result:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a series of nested master pages, like so: site.master: <asp:ContentPlaceHolder ID=SearchFormContent runat=server>
I have two nested repeaters in my *.aspx page. <asp:Repeater runat=server id=rptMain> <ItemTemplate> <h1><%#DataBinder.Eval(Container.DataItem,
I have defined following control template for my custom control. <ControlTemplate TargetType={x:Type local:CustomControl}> <Grid
In _Layout.cshtml I have the following defined in the tag: @RenderSection(JavaScript, required: false); The
In my asp.net MVC 3 application, I have nested layouts. I have followed following
I have an image that has a nested context menu defined in the XAML
I have defined the following class using COM to use the IGroupPolicyObject using C#.NET:
I have defined the following two functions test <- function(t) { return( (0.5*eta^2/theta)*(1-exp(-2*theta*t)) )
I have a nested form in a rails view that is called like this
I have two <div> , one nested into the other defined like this: <div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.