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