Click here to Skip to main content
15,126,105 members
Articles / Web Development / ASP.NET
Posted 24 Oct 2014



Different Items in RadCombobox in Each Row of RadGrid

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
24 Oct 2014CPOL
Different items in RadCombobox in each row of RadGrid with sqlDataSource


For a project, I use a RadComboBox in a templateColumn in a RadGrid to show some data. The combobox should show different items based on the value of a text field on the same row. In order to do this, I populate the sqlDatasource that is bound to the RadComboBox with all possible items and then hide the items I don't need in the combobox of each row.

Using the Code

To achieve this, use the ItemDataBound event of the RadGrid. This event gets fired for every row of the grid:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
if (e.Item is GridDataItem)
GridDataItem item = (GridDataItem)e.Item;
RadComboBox ddl = (RadComboBox)item["Temp"].FindControl("RadComboBox2");
//GridDropDownColumn ddl2 = 
string Name = item["Name"].Text;
int Row = 0; 
SqlDataSource4.ConnectionString = 
SqlDataSource4.SelectCommand = "SELECT RegNr,EQ_ID FROM EQUIPMENT WHERE NAME <> '" + Name + "'";
DataView dv = (DataView)SqlDataSource4.Select(DataSourceSelectArguments.Empty);
int TotalRows = dv.Count;
for (int i = 1; i <= TotalRows; i++)
DataRowView drv = dv[Row];
Row = Row + 1;

As you can see, I use the value of the column "Name" to retrieve as the RegNr that are not of the current equipment item. I then loop through the combobox and hide each of the RegNr's that I selected. In this way, the combo everytime contains only the RegNr of the equipment item of that row.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Netherlands Antilles Netherlands Antilles
No Biography provided

Comments and Discussions

GeneralMy vote of 4 Pin
majid torfi26-Oct-14 6:10
professionalmajid torfi26-Oct-14 6:10 
GeneralRe: My vote of 4 Pin
ATjong27-Oct-14 5:08
MemberATjong27-Oct-14 5:08 
QuestionRepeated query? Pin
Jeffrey T. Fritz24-Oct-14 3:35
sponsorJeffrey T. Fritz24-Oct-14 3:35 
You're connecting to and running your query for each row in the grid. Doesn't that seem like a significant amount of IO that you are adding to the server-side process of your page?

Can we improve the performance of your page by running the query once at the beginning of the page and during the ItemDataBound event apply a filter to a copy of the query results for each combobox that you want to load? I wonder what the performance difference is between your query strategy and a single query and filter strategy would be.
AnswerRe: Repeated query? Pin
ATjong25-Oct-14 8:34
MemberATjong25-Oct-14 8:34 
GeneralRe: Repeated query? Pin
ATjong27-Oct-14 7:18
MemberATjong27-Oct-14 7:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.