Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Fill Gridview - Dropdowlist

Posted on 2006-07-22
3
Medium Priority
?
211 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
  • 2
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

885 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