Find controls in Hierachy Gridview

3 posts, 0 answers
  1. Ganeshkumar
    Ganeshkumar avatar
    7 posts
    Member since:
    Mar 2016

    Posted 19 Apr Link to this post

    Hi,

    In the below code am using dropdowns and listbox controls. I need to bind the value from DB for these controls in code behind.

    <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" ShowStatusBar="true"
    AutoGenerateColumns="False" PageSize="3" AllowSorting="True" AllowMultiRowSelection="False"
    AllowPaging="false" AllowAutomaticDeletes="false" AllowAutomaticInserts="false"
    AllowAutomaticUpdates="false"
    OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnNeedDataSource="RadGrid1_NeedDataSource" >
    <MasterTableView DataKeyNames="EmpID" AllowMultiColumnSorting="True"
    Width="100%" CommandItemDisplay="Top" Name="Students">
    <DetailTables>
    <telerik:GridTableView DataKeyNames="Semester,Grade" Width="100%" runat="server" CommandItemDisplay="Top" Name="Details">
    <ParentTableRelation>
    <telerik:GridRelationFields DetailKeyField="EmpID" MasterKeyField="EmpID"></telerik:GridRelationFields>
    </ParentTableRelation>
    <Columns>
    <telerik:GridEditCommandColumn UniqueName="EditCommandColumn1">
    <HeaderStyle Width="20px"></HeaderStyle>
    </telerik:GridEditCommandColumn>
    <telerik:GridBoundColumn HeaderText="semester" DataField="Semester"></telerik:GridBoundColumn>
    <telerik:GridBoundColumn HeaderText="Grade" DataField="Grade"></telerik:GridBoundColumn>
    <telerik:GridButtonColumn UniqueName="DeleteColumn1" Text="Delete" CommandName="Delete"> </telerik:GridButtonColumn>
    </Columns>
    <EditFormSettings EditFormType="Template" >
    <FormTemplate>
    <table cellspacing="2" cellpadding="1" width="100%" border="0" rules="none" style="border-collapse: collapse;">
    <tr>
    <td style="padding-left: 5px; width: 50%;" align="left">
    <asp:Label ID="Label3" runat="server" CssClass="DisplayLabel" Text="Semester"></asp:Label> <br />
    <asp:DropDownList ID="ddlSemester" runat="server">
    <asp:ListItem Selected="True"> -- Select -- </asp:ListItem>                                                    
    </asp:DropDownList>
    </td>
    <td style="padding-left: 5px; width: 50%;" align="left">
    <asp:Label ID="Label1" runat="server" CssClass="DisplayLabel" Text="Grade"></asp:Label> <br />
    <asp:DropDownList ID="ddlGrade" runat="server">
    <asp:ListItem Selected="True"> -- Select -- </asp:ListItem>
    </asp:DropDownList>
    </td>
    </tr>
    <tr>
    <td colspan="2"></td>
    </tr>
    <tr>
    <td align="right" colspan="2">
    <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
    runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' CssClass="button"></asp:Button>&nbsp;
    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel" CssClass="button"></asp:Button>
    </td>
    </tr>
    </table>
    </FormTemplate>
    </EditFormSettings>
    <NoRecordsTemplate>
    <div>
    There are no records to display
    </div>
    </NoRecordsTemplate>
    </telerik:GridTableView>
    </DetailTables>
    <Columns>
    <telerik:GridEditCommandColumn UniqueName="EditCommandColumn1">
    <HeaderStyle Width="20px"></HeaderStyle>
    </telerik:GridEditCommandColumn>
    <telerik:GridBoundColumn HeaderText="Student ID" DataField="EmpID"></telerik:GridBoundColumn>
    <telerik:GridBoundColumn HeaderText="Student Name" DataField="EmpName"></telerik:GridBoundColumn>
    <telerik:GridBoundColumn HeaderText="Degree" DataField="Degree"></telerik:GridBoundColumn>
    <telerik:GridBoundColumn HeaderText="Department" DataField="Dept"></telerik:GridBoundColumn>
    <telerik:GridButtonColumn UniqueName="DeleteColumn2" Text="Delete" CommandName="Delete"> </telerik:GridButtonColumn>
    </Columns>
    <NoRecordsTemplate>
    <div>
    There are no records to display
    </div>
    </NoRecordsTemplate>
    <EditFormSettings EditFormType="Template" >
    <FormTemplate>
    <table cellspacing="2" cellpadding="1" width="100%" border="0" rules="none" style="border-collapse: collapse;">
    <tr>
    <td style="padding-left: 5px; width: 30%;" align="left">
    <asp:Label ID="Label3" runat="server" CssClass="DisplayLabel" Text="Student ID"></asp:Label>
    <br />
    <asp:TextBox ID="TextBox1" runat="server" Width="90%" Text='<%# Bind("EmpID") %>'></asp:TextBox>
    </td>
    <td style="padding-left: 5px; width: 30%;" align="left">
    <asp:Label ID="Label6" runat="server" CssClass="DisplayLabel" Text="Student Name"></asp:Label>
    <br />
    <asp:TextBox ID="TextBox2" runat="server" Width="90%" Text='<%# Bind("EmpName") %>'></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td colspan="2"></td>
    </tr>
    <tr>
    <td style="padding-left: 5px; width: 30%;" align="left">
    <asp:Label ID="Label7" runat="server" CssClass="DisplayLabel" Text="Degree"></asp:Label>
    <br />
    <asp:ListBox ID="ListBox1" runat="server" Width="50%" AppendDataBoundItems="true" SelectionMode="Multiple">
    <asp:ListItem Selected="True"> -- Select -- </asp:ListItem>
    </asp:ListBox>
    </td>
    <td style="padding-left: 5px; width: 30%;" align="left">
    <asp:Label ID="Label8" runat="server" CssClass="DisplayLabel" Text="Department"></asp:Label>
    <br />
    <asp:ListBox ID="ListBox2" runat="server" Width="50%" AppendDataBoundItems="true" SelectionMode="Multiple">
    <asp:ListItem Selected="True"> -- Select -- </asp:ListItem>
    </asp:ListBox>
    </td>
    </tr>
    <tr>
    <td colspan="2"></td>
    </tr>
    <tr>
    <td align="right" colspan="2">
    <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
    runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' CssClass="button"></asp:Button>&nbsp;
    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel" CssClass="button"></asp:Button>
    </td>
    </tr>
    </table>
    </FormTemplate>
    </EditFormSettings>
    </MasterTableView>
    </telerik:RadGrid>

     

    In code behind

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {

    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
    GridEditableItem item = e.Item as GridEditableItem;

    if (e.Item.OwnerTableView.Name == "Students")
    {
    GridEditFormItem editFormItem = (GridEditFormItem)e.Item;
    ListBox listBox1= editFormItem.FindControl("ListBox1") as ListBox;

    }

    }

    }

    Am getting null value when find the listbox.

    Kindly help me to sort out this issue.

    Regards,

    Ganeshkumar

     

     

     

     

  2. Ganeshkumar
    Ganeshkumar avatar
    7 posts
    Member since:
    Mar 2016

    Posted 21 Apr Link to this post

     

    Hi,

    Along with the above issue Cancel button's also not working inside the EditFormsetting.

    When click the cancel button in Insert or Edit event the form temple is not hide its refresh the grid and show the temple again.

    Regards,

    Ganeshkumar Kaliyamoorthy

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1795 posts

    Posted 22 Apr Link to this post

    Hello Ganeshkumar,

    I have tested your code with dummy data, but the ListBox control is correctly found within the OnItemDataBound event.

    If you have enabled AJAX, could you please temporary disable it and see if any server-side errors are thrown?

    As a temporary workaround for the ListBox you could handle the server-side OnLoad event and provide the data in that event:
    <asp:ListBox ID="ListBox1" runat="server" Width="50%" AppendDataBoundItems="true" SelectionMode="Multiple" OnLoad="ListBox1_Load">

    If the issue persists, please open regular support ticket with attached sample, runnable project replicating the issue, so we can test it locally.


    Regards,
    Konstantin Dikov
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top