hi, there, i need to know if the datagrid and dropdownlist will respond to the button click. At the same time, will this dropdownlist will get the data from database. Please help me. i need the solution in a day.
<%@ Page Language="VB" MasterPageFile="~/Courier.master" Title="Untitled Page" %>
<%@ Import Namespace="System.data.sqlclient" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">
Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)
If Not Page.IsPostBack Then
Dim strConn As String = "server=YourServer;uid=YourUID;pwd=YourPWD;database=NorthWind"
Dim MSSQL As String = "Select [StaffID], [FirstName] from StaffRegis_Table"
Dim MyConn As New SQLConnection(strConn)
Dim objDR As SQLDataReader
Dim Cmd As New SqlCommand(MSSQL, MyConn)
MyConn.Open()
objDR = Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
ddlCustomer.DataSource = objDR
ddlCustomer.DataValueField = "StaffID"
ddlCustomer.DataTextField = "FirstName"
ddlCustomer.DataBind()
MyConn.Close()
End If
End Sub
Sub Page_Change(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
MyDataGrid.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
Sub BindData()
Dim strConn As String = ConfigurationManager.ConnectionStrings("CourierSystemConnectionString").ConnectionString
Dim MSSQL As String = "Select DelBoy from DelDown_Table Where DelBoy=@DelBoy "
Dim MyConn As New SQLConnection(strConn)
Dim ds As DataSet = New DataSet()
Dim da As SqlDataAdapter = New SQLDataAdapter
Dim Cmd As New SqlCommand(MSSQL, MyConn)
da.SelectCommand = cmd
Cmd.Parameters.Add(New SqlParameter("@DelBoy", ddlCustomer.SelectedItem.Value))
da.Fill(ds, "Orders")
MyDataGrid.DataSource = ds.Tables("orders").DefaultView
MyDataGrid.DataBind()
End Sub
Sub GetData(ByVal Source As Object, ByVal E As EventArgs)
BindData()
End Sub
Sub GridOne(ByVal Source As Object, ByVal E As EventArgs)
MyDataGrid.currentpageindex = 0
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<form id="form1" Runat="server">
<asp:DropDownList id="ddlCustomer"
Runat="server"
OnSelectedIndexChanged="GridOne" />
<asp:Button id="button1"
Text="Search"
onclick="GetData"
Runat="server" />
<asp:Datagrid Runat="server"
Id="MyDataGrid"
GridLines="Both"
cellpadding="0"
cellspacing="0"
Headerstyle-BackColor="#BDCFE7"
Headerstyle-Font-Name="Arial"
Headerstyle-Font-Size="8"
BackColor="#E7EFFF"
Font-Name="Arial"
Font-Size="8"
BorderColor="Black"
AllowPaging = "True"
PageSize = "5"
PagerStyle-Mode = "NumericPages"
PagerStyle-HorizontalAlign="Center"
PagerStyle-PageButtonCount = "10"
OnPageIndexChanged = "Page_Change">
</asp:DataGrid>
</form>
</asp:Content>