This is a migrated thread and some comments may be shown as answers.

repetition in ListValueField in Grid

5 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Anto (DLL Version : 2008.3.1314.35) asked on 05 Mar 2009, 07:57 AM
Hi All

I have used a GridDropDownColumn to show show and edit the department field

I have a table with dept field for department.

so I have given ListValueField="dept"

so that all the departments will be displayed.

But repetition occurs. How to avoid it.

Here is my code

<telerik:GridDropDownColumn ListTextField="dept" UniqueName="Udept" ListDataMember="antoempdt" SortExpression="dept" DropDownControlType="DropDownList" ListValueField="dept" HeaderText="Department" DataField="dept">
                        </telerik:GridDropDownColumn>

Thank you in advance

-Anto


5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Mar 2009, 11:53 AM
Hi Anto,

Try the accessing the DropDownList in the ItemDataBound event and remove the repeated items as shown below.

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditFormItem edititem = (GridEditFormItem)e.Item; 
            DropDownList ddl = (DropDownList)edititem["Udept"].Controls[0]; 
            RemoveDuplicateItems(ddl); 
        } 
    } 
 
    private static void RemoveDuplicateItems(DropDownList ddl) 
    { 
        for (int i = 0; i < ddl.Items.Count; i++) 
        { 
            ddl.SelectedIndex = i; 
            string str = ddl.SelectedItem.ToString(); 
            for (int counter = i + 1; counter < ddl.Items.Count; counter++) 
            { 
                ddl.SelectedIndex = counter; 
                string compareStr = ddl.SelectedItem.ToString(); 
                if (str == compareStr) 
                { 
                    ddl.Items.RemoveAt(counter); 
                    counter = counter - 1; 
                } 
            } 
        } 
    } 

Thanks
Shinu
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 05 Mar 2009, 12:04 PM
Hi Shinu

This is from aspx page

<telerik:GridDropDownColumn ListTextField="dept" UniqueName="Udept" ListDataMember="antoempdt" SortExpression="dept" DropDownControlType="DropDownList" ListValueField="dept" HeaderText="Department" DataField="dept">
                        </telerik:GridDropDownColumn>

and it is grid for automatic update delete and addnew.

so how could i change it?

-Anto
0
Shinu
Top achievements
Rank 2
answered on 06 Mar 2009, 06:20 AM
Hi Anto,

The above provided code(for removing the repeated items from DropDownList) does not get affected with Automatic Update/Delete/Insert  set to true/false. If you have set EditMode to InPlace for the Grid you can try with following approach for achieving the same.

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)
        { 
            GridEditableItem edititem = (GridEditableItem)e.Item; 
            DropDownList ddl = (DropDownList)edititem["Udept"].Controls[0]; 
            RemoveDuplicateItems(ddl); 
        }   
 
    } 
    private static void RemoveDuplicateItems(DropDownList ddl) 
    { 
        for (int i = 0; i < ddl.Items.Count; i++) 
        { 
            ddl.SelectedIndex = i; 
            string str = ddl.SelectedItem.ToString(); 
            for (int counter = i + 1; counter < ddl.Items.Count; counter++) 
            { 
                ddl.SelectedIndex = counter; 
                string compareStr = ddl.SelectedItem.ToString(); 
                if (str == compareStr) 
                { 
                    ddl.Items.RemoveAt(counter); 
                    counter = counter - 1; 
                } 
            } 
        } 
    }  


Thanks
Shinu
0
Oscar
Top achievements
Rank 1
answered on 23 Mar 2009, 08:44 PM
How can I do the samething but with repetitive items in a Grid column:
This is just an example:

                    Column1    Column2
Row1:            Oscar        BMW
Row2:            Oscar        Toyota
Row3:            Oscar        Honda

I would like to show my DataGrid like this:
                    Column1    Column2
Row1:            Oscar        BMW
Row2:                             Toyota
Row3:                             Honda

Please help
Oscar.

0
Princy
Top achievements
Rank 2
answered on 24 Mar 2009, 04:01 AM
Hello Oscar,

You can check out the following forum link where a similar scenario as yours has been discussed upon. Hope that you will find it helpful.
If previous row value same don't display

Thanks
Princy.
Tags
Grid
Asked by
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Oscar
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or