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

  • Home
  • SEARCH
  • 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 7080723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:49:49+00:00 2026-05-28T06:49:49+00:00

Hello fellow programmers, got a few problem here. I am adding a user control

  • 0

Hello fellow programmers, got a few problem here. I am adding a user control inside a gridview.
Now my question is how can bind it cause inside the user control is a gridviewthat needs the CourseCatID so that it could bind the datas. And by the way I cannot use nested griview cause I need the render of the nested usercontrol for another purpose. Any tutorial/help will be gladly appreciated.

<asp:GridView ID="grdCategory" runat="server" AutoGenerateColumns="False" Width="1100px"
                DataKeyNames="CourseCatID" Font-Names="verdana,arial,helvetica,sans-serif" Font-Size="8pt"
                CellPadding="4" ForeColor="#333333" GridLines="None">
                <Columns>
                    <asp:ButtonField Text="SingleClick" CommandName="SingleClick" Visible="False" />
                    <asp:BoundField HeaderText="CourseCatID" Visible = "false" DataField="CourseCatID" />
                    <asp:TemplateField HeaderText="Course Category">
                        <ItemTemplate>
                            <asp:Label ID="lblCourseCatID" runat="server" Visible="false" Text='<%# Eval("CourseCatID")%>'></asp:Label>
                                 <a href="javascript:toggleDiv('mydiv<%# Eval("CourseCatID")%>')">
                                 <asp:TextBox ID="txtCourseCatName" runat="server" Text='<%# Eval("CourseCatName") %>' Font-Size="XX-Small"
                            Font-Names="Verdana" Width="300px" Visible="false"></asp:TextBox>
                                <asp:Image ID="img" onclick="javascript:Toggle(this);" runat="server" ImageUrl="~/Images/minus.gif"
                                    ToolTip="Collapse" Width="7px" Height="7px" ImageAlign="AbsMiddle" /></a>
                            <asp:Label ID="lbllastname" Height="15px" runat="server" Text='<%# Eval("CourseCatName")%>'> </asp:Label>
                            <div id="mydiv<%# Eval("CourseCatID")%>">


                                <br />
                              &#160&#160&#160&#160&#160&#160<%--OnClick="ImageAdd_click" --%>
                                <asp:ImageButton ID="ImageAdd" Height="17px" ImageUrl="Images/addCourse.png" runat="server"
                                    CommandName="cmdAdd" CommandArgument='<%# Eval("CourseCatID") %>' />
                                    <br />
                                    <br />

                                    &#160&#160&#160&#160&#160&#160
                                <asp:Panel ID="pnlCourse" runat="server"></asp:Panel>
                                <b><cuc1:CourseUserControl ID="CourseUserControl1" runat="server" /></b>
                                <br />
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <br />
                                 <br />
                                  <br />

                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            </div>
                        </ItemTemplate>
                    </asp:TemplateField>

Thank you for your time

  • 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-28T06:49:49+00:00Added an answer on May 28, 2026 at 6:49 am

    You have a couple of options.

    The easiest one is to expose a public property on the user control that will let you do this:

    <cuc1:CourseUserControl ID="CourseUserControl1" runat="server" CourseCategoryID='<%# (int)Eval("CourseCatID") %>' />
    

    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):

    private int _courseCategoryID;
    public int CourseCategoryID
    {
        get { return _courseCategoryID; }
        set
        {
            _courseCategoryID = value;
    
            // TODO: code that initializes the GridView in user control.
    
            this.DataBind();
        }
    }
    

    Your other option is to expose the same property and handle the RowDataBound event and do this:

    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();
    }
    

    Note that I’m databinding manually instead of immediately after assigning a new category to the user control in the current row.

    For more information, see:
    GridView.RowDataBound Event (ASP.NET 3.5)
    or
    GridView.RowDataBound Event (ASP.NET 4.0)

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

Sidebar

Related Questions

Hello fellow programmers I have been searching the internet for a few days now
Hello , all my fellow coders! I've got a problem ohh chok! .. :P
Hello fellow C++ programmers. I have, what I hope to be, a quick question
hello fellow android programmers, I'm constantly running into the same problem over and over
Hello my fellow programmers, I have a problem (other than not knowing enough) I
hello fellow java developers. I'm having a bit of an issue here. I have
Hello fellow programmers, I have made a function that looks up the database if
Hello Again my fellow programmers out there, I'm designing and programming from scratch a
Hello fellow stackies, I'm developing a site and I have a small problem. It's
Hello fellow programmers. I have a SQL Server 2005 query that is taking a

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.