Solved

Binding to dropdownlist inside datagrid

Posted on 2004-09-08
1
776 Views
Last Modified: 2012-06-27
How do I bind data to a dropdownlist INSIDE a datagrid control?
0
Comment
Question by:bme2you
1 Comment
 
LVL 35

Accepted Solution

by:
YZlat earned 125 total points
Comment Utility
create a separate binding function for example:

Public Function BindState()
        Dim Reader As OleDbDataReader
        Dim sql,strConn As String
      strConn="Your connection string here"
        sql = "SELECT Field1 FROM Table1"
      Dim Conn As OleDbConnection
       Conn = New OleDbConnection(strConn)
        Try
                  Conn.Open()
      Catch ex as Exception
               ''handle your exception
      End Try
        Dim Cmd As OleDbCommand = New OleDbCommand(sql, Conn)
       
        Reader = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

        Return Reader
    End Function

Then call this function from .aspx file from dropdown Item Template:

<asp:TemplateColumn HeaderText="My header">
                                    <ItemTemplate>
                                          <asp:DropDownList id=Dropdownlist1 runat="server" DataMember="Table1" Width="150px" DataValueField="FieldID" DataTextField="Field1" DataSource="<%# BindState() %>">
                                          </asp:DropDownList>
                                    </ItemTemplate>
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

772 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

11 Experts available now in Live!

Get 1:1 Help Now