Solved

Binding to dropdownlist inside datagrid

Posted on 2004-09-08
1
779 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
ID: 12009530
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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/…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 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