Solved

Fill Gridview - Dropdowlist

Posted on 2006-07-22
3
204 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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now