Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 26th, 2006, 01:26 PM
Authorized User
 
Join Date: Mar 2005
Location: , , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default Populating dropdown within a datagrid

I have a datagrid on my web form that needs to contain a dropdown within each row.

Here is the code I have so far:

Code:
HTML: Just the template column of datagrid:
<asp:TemplateColumn HeaderText="Network Access Group"> 
<ItemTemplate>
<asp:DropDownList id="ddlNetworkAccessGroup" DataSource="<%#BindState()%>" DataTextField="sDescription" DataValueField="imsNetworkAccessGroupId " runat="server" Font-Name="Tahoma" Font-Size ="x-small" />
</ItemTemplate>
</ asp:TemplateColumn>

Code Behind:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim bPopulateGrid As Boolean
        Try

        If Not Page.IsPostBack Then
            If Request.Cookies.Count = 1 Then
                Response.Redirect("login.aspx")
            ElseIf Request.Cookies.Count >= 2 Then
                BindState()
            End If
        End If

       Catch ex As Exception
            lblResult.Text = ex.Message
        End Try
End Sub

Public Function BindState()
      Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("connString"))

      Dim myCommand As SqlCommand = New SqlCommand("uspGetNetworkAccessGroup", myConnection)

      myCommand.CommandType = CommandType.StoredProcedure
      myConnection.Open()
      Return myCommand.ExecuteReader(CommandBehavior.CloseConnection)
End Function


This works perfectly....The only thing is I need the first entry in every dropdownlist to be "-SELECT-"

How can I insert that string into every dropdown?



Thanks,
Ninel






  #2 (permalink)  
Old May 26th, 2006, 03:17 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

cross post:
http://p2p.wrox.com/topic.asp?TOPIC_ID=44790

  #3 (permalink)  
Old May 31st, 2006, 03:41 AM
Registered User
 
Join Date: Aug 2003
Location: Sydney, NSW, Australia.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just a quicky tested within a formview.

When you select the dropdown and have a look at it's properties

AppendDataBoundItems = true

In the collection add -Select- and make it selected = true.

paul

 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating dropdown within a datagrid ninel ASP.NET 2.0 Basics 7 May 26th, 2006 04:26 PM
Populating dropdown within a datagrid ninel General .NET 0 May 26th, 2006 01:27 PM
populating a dropdown list within a datagrid in C# akshay144 General .NET 0 May 12th, 2006 05:44 AM
populating dropdown values rupen Classic ASP Basics 16 October 10th, 2005 10:48 AM



All times are GMT -4. The time now is 10:47 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.