Click here to Skip to main content
12,403,535 members (72,835 online)
Rate this:
Please Sign up or sign in to vote.
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">
                        <asp:ButtonField Text="SingleClick" CommandName="SingleClick" Visible="False" />
                        <asp:BoundField HeaderText="CourseCatID" Visible = "false" DataField="CourseCatID" />
                        <asp:TemplateField HeaderText="Course Category">
                                <asp:Label ID="lblCourseCatID" runat="server" Visible="false" Text='<%# Eval("CourseCatID")%>'></asp:Label>
                                     <a href="java<!-- no -->script:toggleDiv('mydiv<%# Eval("CourseCatID")%>')">

Thanks for your time
Posted 19-Jan-12 13:40pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can do something like this on RowDataBound event of the gridview
I am writing an example for textbox
if (e.Row.RowIndex != -1)
     if (e.Row.RowType == DataControlRowType.DataRow)
          TextBox txtCourseCatID = new TextBox;
          txtCourseCatID =  (TextBox)grdCategory.FindControl("Textbox ID here");
          txtCourseCatID.text = "Done";

You can any control like this.
Hope this helped Smile | :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


you can write the rowdatabound event of gridview and then get that control using type casting,

get controls value then whatever you can bind to this and reassign to the control

refer solution1 syntax
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Ive got it but thanks anyway for your help. Ive created a sub wherein i get the coursecatid
here is my code
Private Sub CreateCourseGrid(Optional ByVal parentIsPostBack As Boolean = False)
        'Dim c As Control = GetPostBackControl(Page)
        'If c Is Nothing Then

        For iCatRow As Integer = 0 To grdCategory.Rows.Count - 1
            Dim ccId As String = _
                DirectCast(grdCategory.Rows(iCatRow).Cells(1).FindControl("lblCourseCatID"), Label).Text
            Dim year As String = drpdwnYear.Text
            Dim disciplineId As Integer = DropDownList1.SelectedValue
            _coursesdataDAL = New CoursesDataDAL
            Dim coursedata As New CoursesData
            coursedata.Year = year
            coursedata.CourseCatID = ccId
            coursedata.DisciplineID = disciplineId
            Dim pnlCourse As Panel = DirectCast(grdCategory.Rows(iCatRow).Cells(1).FindControl("pnlCourse"), Panel)
            Dim courseUC As CourseUserControl = LoadControl("~/CourseUserControl.ascx")
            courseUC.CData = coursedata
            courseUC.ParentIsPostBack = parentIsPostBack

        'End If
    End Sub
Ive added some subs and class but that code binds the user control. Works like charm. Thanks to all

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 20 Jan 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100