Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Imports System.Data
Imports System.Data.SqlClient
Partial Class testing
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Me.BindData()
        End If
    End Sub
    Private Sub BindData()
        Dim Query As String = "Select * from Employees"
        Dim Cmd As New SqlCommand(Query)
        GridView1.DataSource = GetData(Cmd)
        GridView1.DataBind()
    End Sub
    Private Function GetData(ByVal Cmd As SqlCommand) As DataTable
        Dim strConnString As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString
        Using con As New SqlConnection(strConnString)
            Using sda As New SqlDataAdapter()
                Cmd.Connection = con
                sda.SelectCommand = Cmd
                Using dt As New DataTable()
                    sda.Fill(dt)
                    Return dt
                End Using
            End Using
        End Using
    End Function
End Class



XML
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="testing.aspx.vb" Inherits="testing" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:DropDownList ID="DropDownList1" runat="server" Height="22px" Width="78px"
            DataSourceID="SqlDataSource1" DataTextField="Employee_Name"
            DataValueField="Employee_Name">
        </asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:wilshireConnectionString4 %>"
            SelectCommand="SELECT Employee_Name FROM Employees"></asp:SqlDataSource>
        <br />
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>

    </div>
    </form>
</body>
</html>
Posted
Comments
Praveen Meghwal 26-Apr-12 4:32am    
Can you please explain what you want to achieve in little detail. You have just posted your code only. You have not specified any thing about what action you want to perform in your page.
narrry 26-Apr-12 5:16am    
Hi Praveen,I wanted to change the gridview values with effecting of dropdownlistSelectedItem with out any posstback method. Can you please re-write the code.
Nikfazan 26-Apr-12 5:01am    
Do you want when you change DropDownList1 value, GridView1 show only the Employee that has been selected by DropDownList1?
narrry 26-Apr-12 5:16am    
Hi Nikfazan,I wanted to change the gridview values with effecting of dropdownlistSelectedItem with out any posstback method. Can you please re-write the code.

1 solution

I wanted to change the gridview values with effecting of dropdownlistSelectedItem with out any posstback method. Can you please re-write the code.
No. Nobody is going to re-write the code for you. We surely can tell how it can be done. You have to try by yourself.

You need to use AJAX. Here you go:
MS: AJAX Videos[^]
Ajax tutorials[^]
AJAX overview[^]
What is ASP.NET Ajax?[^]

Keeping small things aside, in short, you need to put your Grid in an Udpate Panel to enable partial rendering:
UpdatePanel control[^]
UpdatePanel Class[^]
All you need to know with sample code is present and explained.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900