Solved

Binding to dropdownlist inside datagrid

Posted on 2004-09-08
1
778 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Auto Submit on dropdown box 14 67
Time Conversions...both ways 2 16
key press alert 2 21
Obtain data from database .mdb 4 8
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 …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

825 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