Skip to main content

Cascading DropDownLists Inside Telerik RadGrid

protected void RadComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            // Get the Country DropDownList first.
            RadComboBox ddlBranch = (RadComboBox)sender;

            // Get the current GridView Row, from which the DropDownList is selected.
            GridEditableItem currentRow = (GridEditableItem)ddlBranch.NamingContainer;

            // Now let's find the City DropDownList on the same GridView Row.
            DropDownList ddlCity = (DropDownList)currentRow.FindControl("ddlAgent");

            if (ddlBranch != null && ddlBranch.SelectedIndex > 0 && ddlCity != null)
            {
                relife_part2Entities db = new relife_part2Entities();
                int? companyidfk=Convert.ToInt32(ddlBranch.SelectedValue);
                ddlCity.DataSource = db.tbl_policymaster.Where(x => x.companyidfk == companyidfk).ToList();
                ddlCity.DataTextField = "fullname";
                ddlCity.DataValueField = "policyID";
              
                ddlCity.DataBind();
                ddlCity.Items.Insert(0, "Select");
            }
            else if (ddlCity != null)
            {
                ddlCity.Items.Clear();
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Get the Country DropDownList first.
            DropDownList ddlBranch = (DropDownList)sender;

            // Get the current GridView Row, from which the DropDownList is selected.
            GridEditableItem currentRow = (GridEditableItem)ddlBranch.NamingContainer;

            // Now let's find the City DropDownList on the same GridView Row.
            DropDownList ddlCity = (DropDownList)currentRow.FindControl("ddlAgent");

            if (ddlBranch != null && ddlBranch.SelectedIndex > 0 && ddlCity != null)
            {
                relife_part2Entities db = new relife_part2Entities();
                int? companyidfk = Convert.ToInt32(ddlBranch.SelectedValue);
                ddlCity.DataSource = db.tbl_policymaster.Where(x => x.companyidfk == companyidfk).ToList();
                ddlCity.DataTextField = "fullname";
                ddlCity.DataValueField = "policyID";

                ddlCity.DataBind();
                ddlCity.Items.Insert(0, "Select");
            }
            else if (ddlCity != null)
            {
                ddlCity.Items.Clear();
            }
        }


Html Code

  <div>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"></telerik:RadAjaxManager>
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
            <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowSorting="True" DataSourceID="SqlDataSource1" GroupPanelPosition="Top" AllowPaging="True" OnItemCommand="RadGrid1_ItemCommand">
                <MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource1" EditMode="PopUp">
                   
                    <Columns>
                        <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
                        </telerik:GridEditCommandColumn>
                        <telerik:GridBoundColumn DataField="agentcode" DataType="System.Int64" FilterControlAltText="Filter agentcode column" HeaderText="agentcode" SortExpression="agentcode" UniqueName="agentcode">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text="" />
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="agentname" FilterControlAltText="Filter agentname column" HeaderText="agentname" SortExpression="agentname" UniqueName="agentname">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text="" />
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="sponsorcode" DataType="System.Int64" FilterControlAltText="Filter sponsorcode column" HeaderText="sponsorcode" SortExpression="sponsorcode" UniqueName="sponsorcode">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text="" />
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="FatherName" FilterControlAltText="Filter FatherName column" HeaderText="FatherName" SortExpression="FatherName" UniqueName="FatherName">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text="" />
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="HusbandName" FilterControlAltText="Filter HusbandName column" HeaderText="HusbandName" SortExpression="HusbandName" UniqueName="HusbandName">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text="" />
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="PhoneNo" FilterControlAltText="Filter PhoneNo column" HeaderText="PhoneNo" SortExpression="PhoneNo" UniqueName="PhoneNo">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text="" />
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="MobileNo" FilterControlAltText="Filter MobileNo column" HeaderText="MobileNo" SortExpression="MobileNo" UniqueName="MobileNo">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text="" />
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="Rank" DataType="System.Int32" FilterControlAltText="Filter Rank column" HeaderText="Rank" SortExpression="Rank" UniqueName="Rank">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text="" />
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>


                    </Columns>
                    <EditFormSettings EditFormType="Template">
<EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>
                        <FormTemplate>
                            <table class="auto-style1">
                                <tr>
                                  <td>Branch</td>
                                    <td>
                                      
                                        <telerik:RadComboBox ID="RadComboBox1" Runat="server" DataSourceID="SqlDataSource2" DataTextField="Name" DataValueField="Id" AutoPostBack="True" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
                                        </telerik:RadComboBox>
                                       
                                    </td>
                                </tr>
                                <tr>
                                    <td>&nbsp;</td>
                                    <td>
                                        <asp:DropDownList ID="ddlAgent" runat="server">
                                        </asp:DropDownList>
                                    </td>
                                </tr>
                                <tr>
                                    <td>&nbsp;</td>
                                    <td>
                                        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="Name" DataValueField="Id" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                                        </asp:DropDownList>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Text="ddl1" ControlToValidate="DropDownList1" ErrorMessage="RequiredFieldValidator" InitialValue="0"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td>&nbsp;</td>
                                    <td>
                                        <asp:Button ID="Button1" runat="server" Text="Button" />
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Text="agent" ControlToValidate="ddlAgent" ErrorMessage="RequiredFieldValidator" InitialValue="0"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                            </table>
                        </FormTemplate>
                    </EditFormSettings>
                </MasterTableView>
            </telerik:RadGrid>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:relife_part2ConnectionString %>" SelectCommand="SELECT * FROM [agent]"></asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:relife_part2ConnectionString %>" SelectCommand="SELECT * FROM [tbl_companyMaster]"></asp:SqlDataSource>
        </div>




http://www.telerik.com/support/code-library/export-radgrid-content-to-excel-word-csv-pdf-with-ajax-enabled

Comments

  1. Thank you for sharing This knowledge. Excellently written article., if only all bloggers offered the same level of content as you, the internet would be a much better place. Please keep it up!
    web chat support

    ReplyDelete

Post a Comment

Popular posts from this blog

UP TET 2011 Exam Application,UPTET 2011 Result | UPTET 2011 Revised Result

UPTET 2011 Result | UPTET 2011 Revised Result | UPTET 2011 Updated Result |Board of High School and Intermediate Education Uttar Pradesh, Allahabad UP TET Advertisement 2011 and Exam Detail/Admit Card/Call Letter Download UP TET 2011 FORM & DETAILS  GET LATEST DETAIL ABOUT 72825 Primary Teacher Merit List UP TET 2011 Application form submission last date is 18-Oct-2011.Forms will be distributed from PNB bank all over UP.According to latest news Appearing B.Ed student also eligible for TET exam 2011 so they can also submit their forms to concern District.There is no requirement for Rojgar Registration No and Bank receipt within the application form.UP TET 2011 exam results will be avail on http://www.uptet2011.com . Now you can easily get Application from from the P.N.B bank Branches. UPTET 2011 Result | UPTET 2011 Revised Result | UPTET 2011 Updated Result |  Board of High School and Intermediate Education Uttar Pradesh, Al...

DataView Rowfilter With Like % in C#.Net

DataView RowFilter Syntax in C#,ASP.Net Example This example describes syntax of DataView.RowFilter expression. It shows how to correctly build expression string (without "SQL injection" ) using methods to escape values. Column names If a column name contains any of these special characters ~ ( ) # \ / = > < + – * % & | ^ ' " [ ], you must enclose the column name within square brackets [ ]. If a column namecontains right bracket ] or backslash \, escape it with backslash (\] or \\). [C#] dataView.RowFilter = "id = 10″; // no special character in column name " id " dataView.RowFilter = "$id = 10″; // no special character in column name " $id " dataView.RowFilter = "[#id] = 10″; // special character " #" in column name "#id" dataView.RowFilter = "[[id\]] = 10″; // special characters in column name " [id] " Literals String values are enclosed within single qu...

Print Div ,HTML or Table Content in Asp.net Using C#

Following is the code for printing  Div ,HTML or Table to printer using C# in Asp.net < script type ="text/javascript" language ="javascript">     function print()     {     var printFriendly = document.getElementById( "div1" )     var printWin = window.open( "about:blank" , "Voucher" , "menubar=no;status=no;toolbar=no;" );     printWin.document.write( "<html><head><title>Voucher Report</title></head><body><h1>Agent Wise Report</h1>" + printFriendly.innerHTML + "</body></html>" );     printWin.document.close();     printWin.window.print();        printWin.close();     }         </ script > add this script lines in your header section of given page. < div id ="div1"> < table ...