Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 26th, 2006, 12: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, 02: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, 02: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



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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.