Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1005
How to populate drop down based on value of another cell in same row?
posted

I would like to populate a column's drop down provider  with table data based on another column's value in the same row. Is this possible?

  • 12679
    posted

    Hi,

    Let me know if you have any questions with this.

    Thanks.

  • 12679
    Verified Answer
    posted

    Hello davefevold,

     The attached sample shows how can be implemented cascading  WebDropDown in context of WebDataGrid
    The user is able to click on cell from Category column to choose one.  Then when the user click on the next cell from Title column all titles will be filtered on the server based on the chosen category.


    ASPx page:

            <ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="100%" AutoGenerateColumns="false"
                DataSourceID="">
                <Columns>
                    <ig:BoundDataField DataFieldName="CategoryBook" Key="CategoryBook">
                        <Header Text="Category" />
                    </ig:BoundDataField>
                    <ig:BoundDataField DataFieldName="Title" Key="Title">
                        <Header Text="Title" />
                    </ig:BoundDataField>
                </Columns>
                <Behaviors>
                    <ig:EditingCore AutoCRUD="false">
                        <Behaviors>
                            <ig:CellEditing>
                                <CellEditingClientEvents EnteredEditMode="loadDropDownItems"  />
                                <ColumnSettings>                              
                                    <ig:EditingColumnSetting ColumnKey="CategoryBook" EditorID="WebDataGrid1_DropDownProvider1" />
                                    <ig:EditingColumnSetting ColumnKey="Title" EditorID="WebDataGrid1_DropDownProvider2" />
                                </ColumnSettings>
                            </ig:CellEditing>
                        </Behaviors>
                    </ig:EditingCore>
                    <ig:Activation>
                    </ig:Activation>
                </Behaviors>
                <EditorProviders>
                    <ig:DropDownProvider ID="WebDataGrid1_DropDownProvider1">
                        <EditorControl DropDownContainerMaxHeight="200px" EnableAnimations="False" ID="provider1"
                            runat="server" EnableDropDownAsChild="False" DropDownContainerWidth="150px">   
                            <Items>
                                <ig:DropDownItem Key="ASP" Text="ASP" Value="1">
                                </ig:DropDownItem>
                                  <ig:DropDownItem Key="PHP" Text="PHP" Value="2">
                                </ig:DropDownItem>
                                  <ig:DropDownItem Key="JAVA" Text="JAVA" Value="3">
                                </ig:DropDownItem>
                            </Items>                   
                            <Button AltText="" />             
                        </EditorControl>
                    </ig:DropDownProvider>
                    <ig:DropDownProvider ID="WebDataGrid1_DropDownProvider2">
                        <EditorControl DropDownContainerMaxHeight="200px" EnableAnimations="False" runat="server"
                            ID="provider2" OnItemsRequested="eProvider_ItemsRequested" DropDownContainerWidth="180"
                            EnableDropDownAsChild="False">
                            <Button AltText="" />
                        </EditorControl>
                    </ig:DropDownProvider>               
                </EditorProviders>
            </ig:WebDataGrid>
    
    

     

    Code behind:

    public partial class _Default : System.Web.UI.Page 
    {
        Order order = null;
        protected void Page_Load(object sender, EventArgs e)
        {    
            order= new Order();
            WebDataGrid1.DataSource = order.Books;
         }
     
       protected void eProvider_ItemsRequested(object sender, DropDownItemsRequestedEventArgs e)
        {
            Category param = (Category)Enum.Parse(typeof(Category), e.Value.ToString());
     
            List<Book> list = order.Books
                                .ToList()
                                .Where(p => p.CategoryBook == param)
                                .ToList<Book>();
     
            ((WebDropDown)sender).DataSource = list;
            ((WebDropDown)sender).TextField = "Title";
            ((WebDropDown)sender).Items.Clear();
            ((WebDropDown)sender).DataBind();
         
        }
      
        public enum Category
        {
            ASP,
            PHP,
            JAVA
        }
     
        public class Book 
        {
            public Category CategoryBook { getset; }
            public int BookId { getset; }
            public string Title { getset; }
        }
     
        public class Order 
        {
            public List<Book> _books;
            public List<Book> Books { get { return _books; } }
     
            public Order()  
            {       
                //init for books
                _books = new List<Book>();
                _books.Add(new Book() { BookId = 1, CategoryBook = Category.PHP, Title = "Pro PHP: Patterns, Frameworks, Testing and More" });
                _books.Add(new Book() { BookId = 2, CategoryBook = Category.PHP, Title = "Beginning PHP and MySQL: From Novice to Professional, Third Edition" });
                _books.Add(new Book() { BookId = 3, CategoryBook = Category.ASP, Title = "Foundations of ASP.NET AJAX" });
                _books.Add(new Book() { BookId = 4, CategoryBook = Category.ASP, Title = "Beginning ASP.NET 3.5 in C# 2008: From Novice to Professional, Second Edition" });
                _books.Add(new Book() { BookId = 5, CategoryBook = Category.ASP, Title = "Pro ASP.NET MVC Framework" });
                _books.Add(new Book() { BookId = 6, CategoryBook = Category.ASP, Title = "Beginning ASP.NET E-Commerce in C#: From Novice to Professional" });
                _books.Add(new Book() { BookId = 7, CategoryBook = Category.JAVA, Title = "Beginning Java™ EE 6 Platform with GlassFish™ 3: From Novice to Professional" });
                _books.Add(new Book() { BookId = 8, CategoryBook = Category.JAVA, Title = "Practical Liferay: Java–based Portal Applications Development" });
            }
        }
     
    }

    CascadingWDD.zip