.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Display Result in gridview based on dropdownlist

Posted By: Catherine     Posted Date: April 07, 2011    Points:5   Category :VB.Net
I am using vb.net.selecting vlaue in dropdownlist display result in gridvew when button1_click.

Responses
Author: kamlesh             
Posted Date: April 07, 2011     Points: 20   

Check below link.

http://stackoverflow.com/questions/417988/show-number-of-results-in-gridview-based-on-dropdown

Thanks And Regards.
Kamlesh Nikam
Author: shankey             
Posted Date: April 07, 2011     Points: 20   


Hi,

following is the sample code you just have to call
BindGridView() function on your button click event. Hope this will help you

Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not Page.IsPostBack Then
BindGridView()
End If
End Sub
Protected Sub BindGridView()
' this method will bind data to the Grid View control based on the selection of
' the table in the DropDownList. Implementing a Stored Procedure is commented.

Dim objConn As New SqlConnection(ConfigurationManager.ConnectionStrings("cartConnectionString").ConnectionString)
Dim objCmd As New SqlCommand()
Dim objRdr As SqlDataReader = Nothing

objConn.Open()
objCmd.Connection = objConn
' Stored Procedure
'objCmd.CommandType = CommandType.StoredProcedure;
objCmd.CommandType = CommandType.Text

Select Case ddlTables.SelectedValue
Case "tblCategories"
'objCmd.CommandText = "GetAllCategories";
objCmd.CommandText = "Select * from tblCategories"
Exit Select
Case "tblColors"
'objCmd.CommandText = "GetAllColors";
objCmd.CommandText = "Select * from tblColors"
Exit Select
Case Else
Exit Select
End Select

Try
objRdr = objCmd.ExecuteReader(CommandBehavior.CloseConnection)
Finally

gvTables.DataSource = objRdr
gvTables.DataBind()

If Not objRdr.IsClosed Then
objRdr.Dispose()
objRdr.Close()
End If
objConn.Close()
objConn.Dispose()
End Try
End Sub



Shankey


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend