ebahammed Posted August 27, 2003 Posted August 27, 2003 Hello, I have a dataset returned by a webservice. dataset has brNum and brName. How do I display both fields in the dataset as brNum-brName in a listBox ? I want user to see both fields separated by a hyphen, inside a listbox. Example: Albany-032 Somebody help me. Thanks in advance. Quote
*Experts* Nerseus Posted August 27, 2003 *Experts* Posted August 27, 2003 You can add them manually (to an ArrayList for example) and bind, or just fill the ListBox manually. Or you could create an expression column with both fields plus the hyphen and bind to that. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
ebahammed Posted August 28, 2003 Author Posted August 28, 2003 Thanks Nerseus! How do I create an expression? See, the data comes in as dataset to listbox. Also, I need to take what the user selected from the listbox. Need help! Thanks again. Quote
*Experts* Nerseus Posted August 28, 2003 *Experts* Posted August 28, 2003 You will have a separate column in your DataTable and set it's type to string (in your case) and set the Expression property to something like: ds.Tables[0].Columns[0].Expression = "brNum + '-' + brName"; If the brNum or brName fields might be null you can wrap them with IsNull(brNum, '') to convert to empty string. Check out the expression property in the help for Visual Studio. There is a LOT of stuff you can do with them. There's one weird problem with expressions. If you happen to define your DataSets using XSDs and the XSD has an expression column, the expression may not contain any data after you first call dataAdapter.Fill(). What we've seen is that setting the expression to itself will fix this, so in the above use something like: ds.Tables[0].Columns[0].Expression = ds.Tables[0].Columns[0].Expression; -Ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
ebahammed Posted August 29, 2003 Author Posted August 29, 2003 Hello Nerseus, I solved the above problem with the following code! It works well, but I have a new small task to do. And I am not sure how? I need 1 row selected as default when page loads. How do I that with the way I added items into listbox from a dataset that's returned by a webservice? As you have noticed, I am new programming, specially in vb.net! Thank You. Dim myService2 As New localhost1.Service1 Dim dsMyList As New DataSet Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load dsMyList = myService2.GetList() 'Get the one table from the dsGetBranchList. Dim myDataTable2 As DataTable = dsMyList.Tables(0) 'For each row in the Table, display the info. Dim temprow2 As DataRow For Each temprow2 In myDataTable2.Rows lstBranch.Items.Add((temprow2("LongName")) & " - " & (temprow2("Branch"))) Next Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.