Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET 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
 
Old May 26th, 2006, 12:27 PM
Authorized User
 
Join Date: Mar 2005
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











Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating dropdown within a datagrid ninel ASP.NET 2.0 Professional 2 May 31st, 2006 02:41 AM
Populating dropdown within a datagrid ninel ASP.NET 2.0 Basics 7 May 26th, 2006 03:26 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.