Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help... I'm a bit new to asp.net and i'm learning to work with data controls. I would like to know if it's possible to work with more than one listview item on the same page in asp.net? I have two listview controls on the same page and both of the bound to different data sources. On page load only one listview displays data, the other one doesn't show record/data. If it's possible i would like to know how to do it.



Here's my code:
VB
Dim DA As New SqlDataAdapter(Query, conn)
DA.SelectCommand.Parameters.AddWithValue("@borrower_id", BorrowerID)
DA.SelectCommand.Parameters.AddWithValue("@bank_id", BankID)
Dim DS As New DataSet

DA.Fill(DS)

lvDetails.DataSource = DS.Tables(0)
lvDetails.DataBind()

VB
Dim insertCommand As New SqlCommand(Query, conn)
insertCommand.Parameters.AddWithValue("@f_name", DS.Tables(0).Rows(0).Item("First_name"))
insertCommand.Parameters.AddWithValue("@l_name", DS.Tables(0).Rows(0).Item("First_name"))
insertCommand.Parameters.AddWithValue("@customer", DS.Tables(0).Rows(0).Item("customer_name"))
Dim DA1 = New SqlDataAdapter(insertCommand)

Dim DS1 As New DataSet
DA1.Fill(DS1)

otherDetails.DataSource = DS1.Tables(0)
otherDetails.DataBind()


The second listview doesn't show any data.
Posted
Comments
[no name] 19-Nov-15 5:36am    
You can have as many as you want listview control on your page.
Donnie N.I 19-Nov-15 5:38am    
Thanks but how can i do that. i'm assigning a datasource to the listview controls from my code-behind file.
[no name] 19-Nov-15 5:41am    
Does not matter whther you provide datasource from code behind or from source code. Are you sure your second dataset having values? Please debug and check.
Donnie N.I 19-Nov-15 6:17am    
I discovered my second dataset didn't have any data inside it.. Thanks a lot
[no name] 19-Nov-15 6:20am    
you have passed First_Name in your @l_name parameter. Try to change it with proper column name. Hope that will give you result in your dataset.

1 solution

Try changing from
VB
insertCommand.Parameters.AddWithValue("@f_name", DS.Tables(0).Rows(0).Item("First_name"))
insertCommand.Parameters.AddWithValue("@l_name", DS.Tables(0).Rows(0).Item("First_name"))
insertCommand.Parameters.AddWithValue("@customer", DS.Tables(0).Rows(0).Item("customer_name"))

to
VB
insertCommand.Parameters.AddWithValue("@f_name", DS.Tables(0).Rows(0).Item("First_name"))
insertCommand.Parameters.AddWithValue("@l_name", DS.Tables(0).Rows(0).Item("Last_name"))
insertCommand.Parameters.AddWithValue("@customer", DS.Tables(0).Rows(0).Item("customer_name"))

I am just guessing that Last_name is the proper column name.

Be advised that this is not a good way to code.
With all these hard coded indexes you are bound to run into errors eventually.
 
Share this answer
 
v3
Comments
Donnie N.I 1-Sep-16 5:29am    
Thanks a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900