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
140
WebData Grid DropdownList
posted

Hello,

I would like to add a DropDownList to a WebDataGrid in each row. In order to populate the unique dropdownlist for each row I would like to use a DataTable and add the dropdown to each Row in the DataTable.

Is this possible, for example in the Aspx to have something like:

<ig:WebDataGrid ID="Datagrid" runat="server" Height="350px" Width="100%" AutoGenerateColumns="False" >
                                                    <Columns>
                                                        <ig:BoundCheckBoxField DataFieldName="BoundCheckBoxField_0" Key="BoundCheckBoxField_0">
                                                            <Header Text="BoundCheckBoxField_0">
                                                            </Header>
                                                        </ig:BoundCheckBoxField>
                                                        <ig:BoundDataField DataFieldName="Unique Key to Determine Drop Down Values" Key="Unique Key to Determine Drop Down Values">
                                                            <Header Text="Unique Key to Determine Drop Down Values">
                                                            </Header>
                                                        </ig:BoundDataField>
                                                        <ig:BoundDataField DataFieldName="DropDownField" Key="DropDownField">
                                                            <Header Text="DropDownField">
                                                            </Header>
                                                        </ig:BoundDataField></Columns>
                                                    <EditorProviders>
                                                        <ig:DropDownProvider ID="DropDownFieldProvider">
                                                            <EditorControl ID="DropDownField" runat="server" DisplayMode="DropDownField" TextField="DropDownField" ValueField="DropDownField">
                                                                <DropDownItemBinding TextField="DropDownField" ValueField="DropDownField" />
                                                            </EditorControl>
                                                        </ig:DropDownProvider> </EditorProviders>
                                                    <Behaviors>
                                                        <ig:VirtualScrolling>
                                                        </ig:VirtualScrolling>
                                                    </Behaviors>
                                                </ig:WebDataGrid>

and on the back end have:

protected void Datagrid_doDatabinding(){

        DataTable dt = new DataTable("dt");
        dt.Columns.Add(new DataColumn("Unique Key to Determine Drop Down Values", typeof(string)));

        dt.Columns.Add(new DataColumn("DropDownField", typeof(WebDropDown)));

        /*get unique key set from a list of relational items on the server*/
        foreach (uniquekey in uniquekeyset)
        {
            DataRow row = dt.NewRow();

           
            row["Unique Key to Determine Drop Down Values"] = uniquekey;
            WebDropDown NewDropDown = new WebDropDown();

            NewDropDown = get_items(uniquekey); //would return the proper WebDropDown
            

            row["DropDownField"] = NewDropDown ;

          
            dt.Rows.Add(row);
        }

        DataView dv = new DataView(dt);
        PObyAssessment.DataSource = dv;
        PObyAssessment.DataBind();

}

Thanks for any advice on this.

Parents
No Data
Reply
  • 16310
    Offline posted

    Hi Marcelo,

    Thank you for your examples. Though I am a bit confused I believe I have the main idea and will suggest accordingly.

    1) I would like to add a DropDownList to a WebDataGrid in each row.

    Setting some control ( like the DropDown) to act as an EditorProvider for a WebDataGrid column means that it will render on each row in the corresponding column cell. This is the way its working out of the box.

    Setting a DropDown editor provider is as easy as the following ( it is described in details here):

    <ig:BoundDataField DataFieldName="Data" Key="Data">
     <Header Text="Data">
     </Header>
    </ig:BoundDataField>

                    <editorproviders>
                        <ig:DropDownProvider ID="DropDownProvider1">
                            <editorcontrol TextField="Data" ValueField="data">
                            </editorcontrol>
                        </ig:DropDownProvider>
                    </editorproviders>
                    <behaviors>
                        <ig:EditingCore>
                            <Behaviors>
                                <ig:CellEditing>
                                    <ColumnSettings>
                                        <ig:EditingColumnSetting ColumnKey="Data" EditorID="DropDownProvider1" />
                                    </ColumnSettings>
                                </ig:CellEditing>
                            </Behaviors>
                        </ig:EditingCore>
                    </behaviors>

    In code behind the dropdown provider is bound to a data source:

        protected void Page_Load(object sender, EventArgs e)
        {
            DropDownProvider dropdownprovider = (DropDownProvider)WebDataGrid1.EditorProviders["DropDownProvider1"];
            dropdownprovider.EditorControl.DataSource = MakeTable();
        }

    I am also attaching a working sample here. Please note that in this case the DropDown is bound to the same data source field which populates the Data column in the grid. You can of course bind the dropdown to another field or another data source.

    WebDataGrid.zip
Children