Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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).</p> <p>Edit: to show the header columns of the nested gridview in the header of the outer gridview, you could set <code>ShowHeader="false"</code> 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.</p> <p><strong>Edit</strong>: </p> <p>Here is a working test-page. Pick the parts you didn't understand:</p> <p><strong>aspx</strong>:</p> <pre><code> &lt;asp:GridView ID="GrdTransaction" runat="server" OnRowDataBound="GrdTransaction_RowDataBound" AutoGenerateColumns="false"&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="DateOfTransaction" HeaderText="Date Of Transaction" SortExpression="DateOfTransaction" /&gt; &lt;asp:TemplateField&gt; &lt;HeaderTemplate&gt; &lt;table width="100%" cellspacing="0" cellpadding="0" border="0"&gt; &lt;tr&gt; &lt;td&gt;&lt;asp:Label ID="LblFileNameHeader" Text="File-Name" runat="server" /&gt;&lt;/td&gt;&lt;td&gt;&lt;asp:Label ID="LblDownloadHeader" Text="Download file" runat="server" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:GridView ID="GrdDocument" runat="server" ShowHeader="false" GridLines="None" AutoGenerateColumns="false" OnRowCommand="GrdDocument_RowCommand" OnRowDataBound="GrdDocument_RowDataBound"&gt; &lt;Columns&gt; &lt;asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100px"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="LblFileName" Text='&lt;%# Eval("Doc")%&gt;' runat="server" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100px"&gt; &lt;ItemTemplate&gt; &lt;asp:Button ID="BtnDownload" runat="server" CommandArgument='&lt;%# Eval("Doc")%&gt;' CommandName="Download" Text="Download" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p><strong>Codebehind</strong>(converted from vb.net to c#):</p> <pre><code>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; } } </code></pre> <p>I have set the LblFileName's Text poperty in <code>GrdDocument_RowDataBound</code>. That is redundant because i've always used <code>eval</code> on the aspx-page. I wanted to show both ways for the sake of completeness.</p> <p>This is result:</p> <p><img src="https://i.stack.imgur.com/Y7DVf.jpg" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload