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 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 7th, 2007, 12:50 AM
Authorized User
 
Join Date: Aug 2007
Location: , , Singapore.
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to yukijocelyn
Default DetailsView update onclick on LinkButton

Hi

I have another problem again here.
I want an array of LinkButtons to hold the data extracted from the database. My idea is, to click this particular linkbutton, eg: "Amy", it will do a postback, & load the record of "Amy". Below are my codes, but there are not working. Please advise.

Dim searchfield as String

Protected Sub cmdSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim searchvalue As String
        
        Dim selectQuery, dbconn As String
        Dim myConnection As OleDbConnection
        Dim ad As OleDbDataAdapter
        Dim ds As DataSet

        Dim lbtnArrList As ArrayList
        lbtnArrList = New ArrayList
            
        searchvalue = txtSearch.Text
        searchfield = txtField.Text

        dbconn = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("App_Data/DB.mdb")
        selectQuery = "SELECT allocatedID, acct, em, FullName FROM table WHERE " + searchfield + " LIKE '" + searchvalue + "%'"

        myConnection = New OleDbConnection(dbconn)

        ad = New OleDbDataAdapter(selectQuery, myConnection)

        myConnection.Open()
        Dim cmd As OleDbCommand = New OleDbCommand(selectQuery, myConnection)
        Dim reader As OleDbDataReader = cmd.ExecuteReader()

        ds = New DataSet
        Dim totnumrecs As Integer = ad.Fill(ds)

        MsgBox(totnumrecs)

        If totnumrecs = 0 Then
            tblMoreAccts.Visible = False
            DetailsView1.Visible = False
            MsgBox("There is no such account for [" + searchvalue + "]. Please check the name or number and try again.", MsgBoxStyle.Information, "No Account Found.")
        Else
            tblMoreAccts.Visible = True
            Dim lBtn As LinkButton
            While (((totnumrecs = 0) <> True) And reader.Read())

                Dim tblrow As New TableRow
                Dim cell As New TableCell

                lBtn = New LinkButton
                lBtn.Text = reader(searchfield).ToString
                lBtn.CommandArgument = reader(searchfield).ToString
                lBtn.CommandName = "LinkBtnClicked"
                lbtnArrList.Add(lBtn)
                cell.Controls.Add(lBtn)
                tblrow.Cells.Add(cell)
                tblMoreAccts.Rows.Add(tblrow)
            End While

            DetailsView1.DataSource = ds
            DetailsView1.DataBind()

        End If


        myConnection.Close()
        reader.Close()
    End Sub


    Protected Sub DetailsView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventA rgs)
        If e.CommandName.Equals("LinkBtnClicked") Then
            Dim dbconn As OleDbConnection
            Dim sql As String
            Dim dbcomm As OleDbCommand
            Dim dataAdap As OleDbDataAdapter
            Dim ds As DataSet

            dbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data/DB.mdb"))
            dbconn.Open()
            sql = "SELECT allocatedID, acct, em, FullName FROM table WHERE " + searchfield + " LIKE '" + e.CommandArgument + "%'"
            dbcomm = New OleDbCommand(sql, dbconn)
            dataAdap = New OleDbDataAdapter(dbcomm)

            ds = New DataSet
            dataAdap.Fill(ds)

            DetailsView1.DataSource = ds
            DetailsView1.DataBind()

        End If
    End Sub

Is there anything wrong with this piece code? The application just took as if this piece of code didn't exist.
Thank you!
Reply With Quote
  #2 (permalink)  
Old September 10th, 2007, 03:43 AM
Authorized User
 
Join Date: Aug 2007
Location: , , Singapore.
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to yukijocelyn
Default

Hi

I realised that DetailsView1_ItemCommand doesn't do anything unless anything in DetailsView is changed. Therefore that lower piece of codes don't work. When I wanted to try linkbutton's click event, I couldn't find any because I declared it in codes.
How can it do this when on click on these linkbuttons?
I'va tried to change the linkbuttons to buttons, however, they are exactly the same as he linkbuttons.

Please help... Thank you!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Saving Original Data via DetailsView Update kevorkian ASP.NET 2.0 Basics 5 May 29th, 2008 01:47 PM
DetailsView update not working. Andrew.Berry ASP.NET 2.0 Professional 6 April 22nd, 2008 11:23 AM
Cannot Update the vals in a Dynamic DetailsView Itech ASP.NET 2.0 Professional 6 April 2nd, 2008 01:59 AM
linkbutton Beulah VS.NET 2002/2003 3 October 10th, 2005 05:00 PM
linkbutton and postback jtyson ASP.NET 1.0 and 1.1 Professional 1 July 14th, 2003 06:37 PM



All times are GMT -4. The time now is 02:07 PM.


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