Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since you are creating the TextBoxesbased on org.Registrations, you can use a Repeater in the ItemTemplate of GirdVIew and then bind the org.Registrations as DataSource to the repeater in the RowCreated event. i.e: <strong>in your aspx:</strong></p> <pre><code>&lt;asp:GridView ...... OnRowDataBound="gv_RowDataBound"&gt; . . . &lt;asp:TemplateField ...&gt; &lt;ItemTemplate&gt; &lt;asp:Repeater id="rptRegistrations" runat="server"&gt; &lt;asp:TextBox id="txtRegistration" runat="server" Text='&lt;%#Eval("Name")%&gt;'&gt;&lt;/asp:TextBox&gt;&lt;br/&gt; &lt;/asp:Repeater&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField ...&gt; &lt;/asp:GridView&gt; </code></pre> <p><strong>in your code behind</strong> </p> <pre><code> protected void gv_RowDataBound(object sender, GridViewRowEventArgs e) { if(e.Row.RowType == DataControlRowType.DataRow) { Students org = (namespace.Students )(e.Row.DataItem); Repeater rptrRegistrations = e.Row.Cells[7].FindControl("rptrRegistrations") as Repeater ; rptrRegistrations.DataSource = org.Registrations; rptrRegistrations.DataBind(); } } public void gv_SelectedIndexChanged(Object sender, EventArgs e) { // Get the currently selected row using the SelectedRow property. GridViewRow row = gvOrg.SelectedRow; Repeater rptrRegistrations = row.Cells[7].FindControl("rptrRegistrations") as Repeater; foreach(RepeaterItem item in rptrRegistrations.Items) { TextBox txtRegistration = item.FindControl("txtRegistration") as TextBox; //Now you have access to the textbox. } } </code></pre> <p><strong>Ignore the following text based on OP's comment</strong></p> <p>Instead of creating the TextBox dynamically, add the Textbox in the Grid ItemTemplate in ASPX and then use e.Row.Cells.FindControl to access the textbox. Something like:</p> <pre><code>protected void gv_RowCreated(object sender, GridViewRowEventArgs e) { Students org = (namespace.Students )(e.Row.DataItem); foreach (Registration reg in org.Registrations) { int _count = org.Registrations.Count; for (int rowId = 0; rowId &lt; _count; rowId++) { TextBox txtBox = e.Row.Cells[7].FindControl("txtRegistration") as TextBox ; //txtBox.ID = "_registration" + e.Row.RowIndex + "_" + rowId; txtBox.Text = reg.Name; txtBox.Visible = true; //e.Row.Cells[7].Controls.Add(txtBox); } } } </code></pre>
    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