Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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="java<!-- no -->script: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 />
                                        <%--OnClick="ImageAdd_click" --%>
                                    <asp:ImageButton ID="ImageAdd" Height="17px" ImageUrl="Images/addCourse.png" runat="server"
                                        CommandName="cmdAdd" CommandArgument='<%# Eval("CourseCatID") %>' />
                                        <br />
                                        <br />
                                        
                                              
                                    <asp:Panel ID="pnlCourse" runat="server"></asp:Panel>
                                    <cuc1:CourseUserControl ID="CourseUserControl1"  runat="server" />
                                    <br />
                                               
                                    <br />
                                     <br />
                                      <br />
                                      
                                         
                                </div>
                            </ItemTemplate>
                        </asp:TemplateField>


Thanks for your time
Posted

You can do something like this on RowDataBound event of the gridview
I am writing an example for textbox
C#
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 :)
 
Share this answer
 
hi,

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
 
Share this answer
 
Ive got it but thanks anyway for your help. Ive created a sub wherein i get the coursecatid
here is my code
VB
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
            'e.Row.Cells(1).Controls.Add(courseUC)
            pnlCourse.Controls.Add(courseUC)


        Next
        'End If
    End Sub

Ive added some subs and class but that code binds the user control. Works like charm. Thanks to all
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900