Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have a couple of options.</p> <p>The easiest one is to expose a public property on the user control that will let you do this:</p> <pre><code>&lt;cuc1:CourseUserControl ID="CourseUserControl1" runat="server" CourseCategoryID='&lt;%# (int)Eval("CourseCatID") %&gt;' /&gt; </code></pre> <p>Then databind in the user control as soon as that property is assigned to. Note that I'm assuming the category is an Int32. For example (note that the CourseCategoryID stores its value in a private field, not in ViewState):</p> <pre><code>private int _courseCategoryID; public int CourseCategoryID { get { return _courseCategoryID; } set { _courseCategoryID = value; // TODO: code that initializes the GridView in user control. this.DataBind(); } } </code></pre> <p>Your other option is to expose the same property and handle the RowDataBound event and do this:</p> <pre><code>if (e.Row.RowType == DataControlType.DataRow) { CourseUserControl courseDetails; courseDetails = (CourseUserControl)e.Row.FindItem("CourseUserControl1"); // Assuming category ID is Int32 courseDetails.CourseCategoryID = (int)grdCategory.DataKeys[e.Row.RowIndex].Value; courseDetails.DataBind(); } </code></pre> <p>Note that I'm databinding manually instead of immediately after assigning a new category to the user control in the current row.</p> <p>For more information, see: <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound%28v=vs.90%29.aspx" rel="nofollow">GridView.RowDataBound Event (ASP.NET 3.5)</a> or <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound%28v=vs.100%29.aspx" rel="nofollow">GridView.RowDataBound Event (ASP.NET 4.0)</a></p>
    singulars
    1. This table or related slice is empty.
    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