|
Hi all. I have wrestled with this for a week now.
I have a website in .net 2.0, created with VWD Express, and I use VB in my code. The site is designed to sell size based products. I have a reasonable amount of experience with VBA in Access databases, but I'm struggling to get to grips with this new way of thinking when working with online applications. Please excuse my ignorance with terminology etc.
In Access, I was able to use a combobox to hold a recordset. For example, my combox could hold this info:
OptionName | OptionPrice | PriceMethod
------------------------------------------------
Pink £10.00 1
Brown £12.00 1
White £5.00 2
Red £9.00 3
In access, the CB would be populated with all the above detail on the PageLoad event with all the options for a particular product.
Usually, in Access, I could quickly reference the 2nd and 3rd column values in code and make calcualtions on them.
This would enable me to quickly re-price an option if the CB value is changed without going back to the database. This makes so much more sense than waiting for a round trip to the DB, and means that price calculations are instant.
How can I recreate this in asp.net?
I have investigated some custom controls which mimic ComboBoxes, but I'm struggling to get them to work properly, and what I've seen so far don't really seem that stable.
I have questioned whether it's possible to send the Recordset to a hidden field or viewstate, but having scanned lots of newsgroups I can't find any examples of similar situations, so I'm reluctant to waste days investigating. I'm also unsure on how to reference the table values in code, since I can't find any documentation.
I thought about using a multi array variable, but again, this seems a little crude and long-winded given the simple task I need to acheive.
Worst case, is that I'll probably have to use Ajax to make a trip to the DB. But I simply can't believe that Microsoft would replace the CB with that feeble Drop Down List. Surely there's a simple way???
Any inspiration would be appreciated.
Thanks.
|
|
|
|
|
You can use a gridview to show columnar data. A drop down can show them only as a single string. You can hide data against that tho, a drop down has a data field to go with the field that is shown.
Ginozzzz wrote: But I simply can't believe that Microsoft would replace the CB with that feeble Drop Down List. Surely there's a simple way???
Your core issue is that you don't understand what's going on here. ASP.NET creates websites. So, Microsoft is not at liberty to decide what goes on, they are creating a framework which generates HTML and CSS. Your options are indeed AJAX, or simply using javascript to grab the values needed from the box when a selection changes, and showing the result. That's how web developement works. Microsoft did not invent HTML, CSS or AJAX, they merely provide libraries to help people use them.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hi Gino,
Grid view would be better option (Graus is right on that account)
But if you are using DropDownList then after data bind ,
You have to loop through all the ListItem
and add attribute like "optionPrice" and "PriceMethod"
to each list item
As example in the below code snippet
ListItem Li=ddlAll.Items[itemno];
Li.Attributes.Add("optionPrice",dt[itemno]["optionPrice"])
|
|
|
|
|
Thankyou Graus and Nishant for your replies.
Graus, I don't need to show the user the 2nd and 3rd columns. They are there solely for the purpose of looking up record information without going back to the DB.
IF it where possible to have a hidden gridview, then I could look up the record from the Grid, based on the value selected in the DDL.
Nishant, are you saying that once I bound the data to the DDL, I can add columns(unseen) to the DDL, and populate them from the datatable, effectively giving me exactly what I want?
Thanks again.
|
|
|
|
|
Ya exactly ...but you have to do it ....For each Item in DropDownList
|
|
|
|
|
Ok, I'll have a play around. I'll post the results.
|
|
|
|
|
Okay, I'm a little stuck. I have posted my code of how I am filling my DDL. I am using a datareader.
Protected Sub FillOptionsList()
ddl1.Items.Clear()
Dim sqlStr As String = "SELECT Option1, Option2, Option3 FROM TblOptions WHERE Bid=1"
Dim con As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("myConnection").ConnectionString)
Dim cmd As New SqlCommand(sqlStr, con)
Dim reader As SqlDataReader
Try
con.Open()
reader = cmd.ExecuteReader()
Do While reader.Read()
Dim newItem As New ListItem()
newItem.Value = reader("Option1").ToString()
newItem.Text = reader("Option2")
ddl1.Items.Add(newItem)
Loop
reader.Close()
Catch ex As Exception
Label1.Text = "Error Reading list" & " " & Err.Description
Finally
con.Close()
End Try
End Sub
Please can you help me with the code to get option3 into an 'unseen column' within the DDL? I have tried a few things (not posted) but with no success, and I can't find any help online for this feature.
Thanks.
|
|
|
|
|
Hi all, i have a little problem that even i don't know like solve. I know that is possible but I don't know how.
I have a project ASP.NET with VBasic.NET
I want to add a dropdownlist to DetailsView with diferent source that detailsview.
I put my code and the error:
Dim InsertComboUsuarios As DropDownList = DirectCast(detailsView.FindControl("InsertComboUsuarios"), DropDownList)
Dim UsuariosServicios As New DataTable
UsuariosServicios = Servicios.ObtenerUsuariosServicios()
InsertComboUsuarios.DataSource = UsuariosServicios
InsertComboUsuarios.DataTextField = UsuariosServicios.Columns("Usuario").ColumnName.ToString()
InsertComboUsuarios.DataValueField = UsuariosServicios.Columns("IdUsuario").ColumnName.ToString()
InsertComboUsuarios.DataBind()
the code in aspx:
<asp:TemplateField HeaderText="Usuario del Servicio" >
<ItemTemplate>
<asp:Label ID="lblUsuario" Text='<%# Eval("Id_Usuario") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="EditComboUsuarios" runat="server"></asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="InsertComboUsuarios" runat="server"></asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
and the error is:
System.NullReferenceException was caught
Message="Referencia a objeto no establecida como instancia de un objeto."
Source="App_Web_ie3hu1zc"
The source failed when pass by InsertComboUsuarios.DataSource = UsuariosServicios
some idea?
thanks very much for your help
|
|
|
|
|
Hi Sandraa,
I have done this many times. I don't know exactly why it does not work for you (did not try it out), however, I want to show you a snippet of my working code. Besides being C# the main difference is that I use declarative syntax only:
First the dropdown declaration in the .aspx file:
<br />
<asp:dropdownlist ontextchanged="OnTextChanged" xmlns:asp="#unknown"><br />
SelectedValue='<%# Bind("fake_flag1")%>' <br />
ID="ddl_test1" <br />
DataSourceID="TestDS" <br />
DataTextField="someDescription" <br />
DataValueField="someID" <br />
runat="server"><br />
</asp:dropdownlist><br />
Next the declaration of the datasource for the above dropdown, which is different of the detailsview the dropdown is in:
<br />
<asp:sqldatasource id="TestDS" runat="server" connectionstring="<%$ ConnectionStrings:ConnectionString %>" xmlns:asp="#unknown"><br />
SelectCommand="SELECT * FROM TEST"><br />
</asp:sqldatasource><br />
Hope this helps. Maybe the problem in your code is the point in time when you try to set the datasource?
Cheers,
Marcelo
|
|
|
|
|
Thanks Marcelo but your code is for aspx and I am using aspx.vb, I don't know like call well to dropdownlist from aspx.vb page and from detailsview.
Remenber that my dropdownlist is into a detailsview
Thanks for all
|
|
|
|
|
Sandraa wrote: but your code is for aspx and I am using aspx.vb
Yes, he said you'd have to convert C# to VB, that's trivial to do. Also, he said he's doing it in the aspx, is there any reason you can't try it that way ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hi Sandraa,
Are you sure
Dim InsertComboUsuarios As DropDownList = DirectCast(detailsView.FindControl("InsertComboUsuarios"), DropDownList)
This line is returning you a DropDownList object ???
That is to say InsertComboUsuarios is not null ??
|
|
|
|
|
I believe that yes, I put you the code in aspx page
<asp:TemplateField HeaderText="Usuario del Servicio" >
<ItemTemplate>
<asp:Label ID="lblUsuario" Text='<%# Eval("Id_Usuario") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="EditComboUsuarios" runat="server"></asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="InsertComboUsuarios" runat="server"></asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
I believe that I have put something bad in this code.
Thanks for your help.
|
|
|
|
|
S.O.S
Even I continue with this problem, please any idea?
|
|
|
|
|
How to load any configuration file other than web.config ? It may be a custom configuration file.
|
|
|
|
|
I didn't know, but gosh[^], it sure was easy to find out.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hello,
Can you help me,to get a free hosting of ASP with Mysql, i try for brinkster, unfortunatly they aren't Mysql, thank you verry mutch
modified on Sunday, December 14, 2008 1:13 PM
|
|
|
|
|
You mean ASP.NET, right ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
|
I just wonder if it really matters between MSSQL and MySQL. In my opinion, it is best to keep MSSQL bundled with ASP.NET.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
No, MySQL is better, because, it's FREE, dude. I mean, it's not ACTUALLY free, and SQL Server express IS, but let's not get confused by facts here....
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Mysql or sqlserver, i need the free hosting, help me please
|
|
|
|
|
I have no idea, I tend to prefer to pay my way and to know if I need a website up, I have a reason to expect it to stay up. There are free servers tho, have you tried to google ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
True, but what I was meaning was usually most web hosts will bundle MSSQL with their hosting packages. I do not know of many that have MySQL and ASP together. Usually most that have MySQL are LAMP setups. I've seen a few that swing both ways, not many though.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
hello,
i have created an application who's platform are asp.net1.1,windows XP,Access 2002 and its working fine in my PC.
When i aploaded it on a server who's platform is .NET Framework 2.0,windows server 2003,Access 2003 and when i am browsing a page who has database connectivity it throws an error as 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine".
I tried installing latest MDAC on the server but still showing the same problem.
Thank you.
coolsatty
|
|
|
|