473,378 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

DetailsView update onclick on LinkButtons in ArrayList

Hi

I have a problem 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 all the records of names that start with "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!
Sep 10 '07 #1
2 1726
Hi yukijocelyn]Hi

Try trim... it might help
searchvalue = txtSearch.Text.Trim
searchfield = txtField.Text.Trim

Best Regards,
Ruel




Hi

I have a problem 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 all the records of names that start with "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!
Sep 10 '07 #2
Hi!

Thank you for replying, however, I don't think the problem I'm facing is not the searchvalue that has extra characters.

I'm looking for a click event on the linkbuttons in the array which I added to a table to diaplay them. I would like to click on the linkuttons, & it will update or refresh the DetailsView that I have to the one that I clicked.
However, I couldn't find the click event for it.

How can I go about it?
Sep 10 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Andrew Robinson | last post by:
Is there any way to accomplish two way data binding in a Details View with a DataSet or DataTable as the DataSource. All I want is to get an updated DataSet or DataTable back from the...
12
by: Jim Hammond | last post by:
I am passing the whole object instead or parameters in my select and update methods. I can get the updated object if I set UpdateMethod, let ASP.NET autogenerate an update button, and then press...
0
by: jeffmagill | last post by:
Hi Everybody, I'm really hoping that someone can help me out because I have spent too much time on this project already! Basically, I have a DetailsView that handles all the Edits for a...
4
by: Kjell Arne | last post by:
Hi! I have a detailsview control in a webpart with some templated fields on. I set the ValidationGroup property to som value on these fields to distinguish from other web parts on the page....
6
by: Andrew Robinson | last post by:
I have a page that contains a number of link buttons that are used for making selections. I load my LinkButtons during the Page_PreInit event and they render fine but then I need to make a change...
7
by: studio60podcast | last post by:
I have a gridview and a details view in a page. The two are hooked up, so that when a row is selected in the GridView, the DetailsView displays the details. But, what I'm trying to accomplish is...
1
by: ledneh | last post by:
I've been working on concurrency checking for an application I'm building, and a minor part of it has me slightly stumped. I've got a DetailsView that populates from an ObjectDataSource, using...
0
by: dayiku | last post by:
I am trying to retrieve values from a boundfield in a detailsview. protected void BtnViewDetails_Click(object sender, EventArgs e) { // get the gridviewrow from the sender so we...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.