Solved

Fill Gridview - Dropdowlist

Posted on 2006-07-22
3
207 Views
Last Modified: 2008-02-01
How can I select the element from dropdowlist and display a record on Gridview?




Imports System.Data
Imports System.Data.SqlClient  


 Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click


        Dim StrConnection As String = "mystring"
        Dim Con As New SqlConnection(StrConnection)
        Dim StrCommand As String = "select *from logmein where ?????????????????????????? - "
        Dim Da As New SqlDataAdapter(StrCommand, Con)
        Dim table As New DataTable


        Da.Fill(table)


        GridView1.DataSource = table
        GridView1.DataBind()


   

    End Sub
0
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17162969
Imports System.Data
Imports System.Data.SqlClient  


 Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

        Dim userID As String = Me.DropDownList1.SelectedValue

        Dim StrConnection As String = "mystring"
        Dim Con As New SqlConnection(StrConnection)
        Dim StrCommand As String = String.Format("select * from logmein where userID =  '{0}' ", userID)
        Dim Da As New SqlDataAdapter(StrCommand, Con)
        Dim table As New DataTable

        Da.Fill(table)

        GridView1.DataSource = table
        GridView1.DataBind()

    End Sub

Bob
0
 

Author Comment

by:VBdotnet2005
ID: 17163436
I still new. Could you explain this a little bit? I haven't seen used before.

 Dim StrCommand As String = String.Format("select * from logmein where userID =  '{0}' ", userID)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17163590
If you look up String.Format, it is a shared member of the String class that takes a variable number of arguments {0}, {1}, ..., {n} and replaces them in the string.  It is a much cleaner way of building a formatted string, given certain inputs, versus using string concatenation (userID = '" & userID & "'").  Each of the arguments gets replaced in the string, so userID = 0.  

Another example:

  Dim test As String = String.Format("Item #1 = {0}, Item #2 = '{1}', Item #3 = {2}", item1, item2, item3)

Bob
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question