Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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
 
Old September 20th, 2006, 05:42 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default Get Data from Datagrid

Hi All,

I have a datagrid that has one column built from a querystring. The datagrid also has a ddl in it. I want to use data in the datagrid to insert entries into a look up table that will be used to clean data that is being uploaded from Excel files. I saw some code in C# that used the headertext and a for loop to get the data I'm just not sure how to go about it in VB.

Here's the code to get the first column into the datagrid:

Code:
Dim CompsNot As Array

CompsNot = Split(_Comps, ", ")
Dim i As Integer
Dim Values As New ArrayList
For i = 0 To UBound(CompsNot)
    Values.Add(Replace(CompsNot(i), ",", ""))
Next
grdCompsNot.DataSource = Values
grdCompsNot.DataBind()
Here is the front page code where I'm also adding the ddl and calling a function to populate the ddl.
Code:
<asp:DataGrid ID="grdCompsNot" AutoGenerateColumns="False" Runat="server" class="datagrid" >
<Columns>
<asp:templatecolumn headertext="Bad Name">
<itemtemplate>
<%# Container.DataItem %>
</itemtemplate>
</asp:templatecolumn>
<asp:TemplateColumn HeaderText="Good Name">
<ItemTemplate>
<asp:DropDownList ID="ddlCompID" Runat="server"  DataTextField = "GoodName" DataValueField = "CompID" DataSource='<%# getCompID() %>' />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Any help would be greatly appreciated.

Thanks.

Richard

 
Old September 20th, 2006, 07:04 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

OK.

Since I already knew how to get data from a repeater, I changed the datagrid to a repeater and can now use the code below to access the data in the repeater.

Code:
    Protected Sub rptComponentAliases_ItemDataBound(ByVal s As Object, ByVal e As RepeaterItemEventArgs) Handles rptComponentAliases.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim litCompAliasName As Literal = e.Item.FindControl("litCompAliasName")
            Dim ddlCompID As DropDownList = e.Item.FindControl("ddlCompID")
            Dim SQL As String = "SELECT CompID, CompName FROM Components WHERE Status = 1 ORDER BY CompName;"
            Dim oDA As New SqlDataAdapter(SQL, _oConn)
            Dim oDS As New DataSet
            oDA.Fill(oDS)
            litCompAliasName.Text = e.Item.DataItem
            ddlCompID.DataSource = oDS
            ddlCompID.DataTextField = "CompName"
            ddlCompID.DataValueField = "CompID"
            ddlCompID.DataBind()
            ddlCompID.Items.Insert(0, New ListItem("", 0))
        End If
    End Sub

    Protected Sub btnSave_Click(ByVal s As Object, ByVal e As EventArgs) Handles btnSave.Click
        Try
            _oConn.Open()
            For Each i As RepeaterItem In rptComponentAliases.Items
                Dim litCompAliasName As Literal = i.FindControl("litCompAliasName")
                Dim ddlCompID As DropDownList = i.FindControl("ddlCompID")
                If ddlCompID.SelectedValue > 0 Then
                    Dim SQL As String = "INSERT INTO ComponentAliases (CompID, CompAliasName, Status) VALUES (" & ddlCompID.SelectedValue & ", '" & litCompAliasName.Text & "', 1);"
                    Dim CMD As New SqlCommand(SQL, _oConn)
                    CMD.ExecuteNonQuery()
                End If
            Next
        Catch ex As Exception
        Finally
            _oConn.Close()
        End Try
    End Sub


Works like a champ.

Any comments are greatly appreciated.

Thanks,
Richard


 
Old September 25th, 2006, 11:28 PM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hey richard, im curious are you from Jacksonville FL and did you grow up near Phillips Highway?
peace
carywhittier.com





cwhittier





Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting data into DataGrid edurazee C# 2005 1 July 28th, 2008 05:51 PM
Save data from within a DataGrid edurazee ADO.NET 0 July 28th, 2008 09:15 AM
Highlit the new data over the old data in DataGrid kotanaresh_2003 ASP.NET 1.0 and 1.1 Basics 0 April 12th, 2007 10:26 PM
How can i show data in datagrid? Blueman137 ASP.NET 1.0 and 1.1 Basics 0 March 30th, 2004 08:31 PM





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