Solved

Fill Gridview - Dropdowlist

Posted on 2006-07-22
3
209 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

635 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