dropdownlist within a datagrid - programatically setting the selectedindex when page loads and after an update button pressed

Posted on 2005-04-06
Last Modified: 2008-01-09

I am sure this is done all the time, but I am relatively new to ASP.NET (PLEASE NOTE: project also contains considerable VB.NET - I'd rather have as little on the HTML page and as much code in the .vb files as possible).

We have 3 drop down list's within a datagrid each with different information in them.
All rows within the datagrid are editable.
At the moment it is a static number of rows (15).

What I need to be able to do, is when we load from a table into the grid (binding a dataset) and load from another table into the combo boxes using DataSource="<%# BindCostCentre() %>" on the HTML page (where bindcostcentre code in .vb returns Return cmdCommand.ExecuteReader(CommandBehavior.CloseConnection)) the lists need to be set to a default (based on a value I can retrieve in the database).

EG the list might contain:
Project A
Project B
Project C
Project D
Each row loads from the database via code in the .vb which is already written and working, however the combo box is always defaulting to the first list item, I need it to point to different items depending on which row it is on.
Row 1's drop down needs to point to Project C
Row 2's drop down needs to point to Project B

Basically I need to assign selectedindex on a per row basis on page load/bind for the combo boxes.

Hope this isn't too confusing, but please ask questions if it is.
Thanks for your help,
Question by:brianb99999
    LVL 11

    Accepted Solution

    You can set to particular listitem in dropdown list in datagrid's ItemDatabound event by findind particular dropdown controls using find control method.

    LVL 5

    Author Comment

    Sachi your a Saint  - thanks


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now