How to programmatically bind data to a dropdown list (combobox) in a gridview control for ASP 2.0

How can I programmatically bind data to a dropdown list (combobox) in a gridview control for ASP 2.0. I have a dataset that I am using to bind data to a gridview control that has all columns as labels. I am using the following code to bind my data:

'This method gets me the data to the TVData datatable variable

TVData = objSQL.GetHeader(ClientCode, DivisionCode, Market, Year, Month, MediaType)

'Here I am binding my datatable to my gridview control            

gvTV.DataSource = TVData
gvTV.DataBind()

As a  result I see all my label columns in the gridview populated with the data. However my column containing the combo box is not populated. Any ideas or code, is there any event where you have to write that code?

Thanks in advance
LVL 2
smkkaleemAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aki4uCommented:
Hi,

You need to set few fields in combobox so it gets populated, something like this:

<asp:TemplateColumn HeaderText="HeaderText">
     <ItemTemplate>          
          <asp:DropDownList runat="server" id="cmbID" AutoPostBack="true" OnSelectedIndexChanged="cmb_SelectedIndexChanged" DataSource='<%# GetCmbDataSource() %>' DataTextField="cmbTextField" DataValueField="cmbValueField" >
               </asp:DropDownList>
        </ItemTemplate>
</asp:TemplateColumn>

and of course implement in codebehind "GetCmbDataSource "

OR


Look here:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21271322.htm

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21281459.html
0
smkkaleemAuthor Commented:
I  tried to follow the first link, does not work. The second link talks about the datgrid control for VS 1.1.  My question is regarding the gridview control in ASP.NET 2.0. Any more examples?

Thanks
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
meomarCommented:
Hi,


I think what you need to do is to  grab that control on the Item Creadted event of  the gridview or datagrid. Make sure that you get it while it is not created in the header or the footer. Once you find it you can bind to it in the event.
It will be something like this:

 private void  R_ItemCreated(object sender, System.Web.UI.WebControls.XXXXItemEventArgs e)
            {

                  if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
                  {
                              lstFacility = (DropDownList) e.Item.FindControl("ddFacility");
                              lstFacility.DataSource = htFacility;
                              lstFacility.DataTextField = "value";
                              lstFacility.DataValueField = "key";
                              lstFacility.DataBind();
                                             
                  }
                                }
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.