Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking 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 Basics 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:16 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


 
Old May 26th, 2006, 02:15 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Try ..
ddlNetworkAccessGroup.Items.Insert(0, "--Select--")

You will need to do this in the ItemDataBound event of the grid. Get a refernce to the ddl and use the code above.


 
Old May 26th, 2006, 02:23 PM
Authorized User
 
Join Date: Mar 2005
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. That worked.

 
Old May 26th, 2006, 02:23 PM
Authorized User
 
Join Date: Mar 2005
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. it worked

 
Old May 26th, 2006, 02:36 PM
Authorized User
 
Join Date: Mar 2005
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks...That worked.

Now for another question. I have an Update button next to each dropdown.
How do I capture that the update button was clicked and then capture the selection of the dropdown?

Thanks,
Ninel

 
Old May 26th, 2006, 02:48 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You are gonig to have a button on each row? If so, why? I would just have a single update button outside of the grid.


 
Old May 26th, 2006, 02:51 PM
Authorized User
 
Join Date: Mar 2005
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'll try that. I thought it would be better to jst update the records that need to be updated instead of everything within the grid.

Thanks.

 
Old May 26th, 2006, 03:26 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

the use the built in Edit, Update, Cancel command buttons in the datagrid.






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 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.