Click here to Skip to main content
Rate this: bad
good
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">
                    <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 19-Jan-12 14:40pm
janwel1.9K
Rate this: bad
good
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 | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
good
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
            '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
  Permalink  

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

  Print Answers RSS
0 Maciej Los 315
1 OriginalGriff 233
2 Aajmot Sk 224
3 Richard MacCutchan 220
4 Marcin Kozub 210
0 OriginalGriff 7,853
1 Sergey Alexandrovich Kryukov 7,107
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 20 Jan 2012
Copyright © CodeProject, 1999-2014
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