Morpheusweb.it - Risorse per webmaster: script, ASP.NET, C#, Visual Basic .Net, tutorial, asp, javascript, css, php, html, java, ADO, VBScript, forms, frames, Active Server Pages, Dynamic HTML, database, gratis per webmaster e webdesigner

DropDownList Postback - << C# VERSION >>


Use IsPostBack page property to avoid the reload a DropDownList on PostBack


<%@ Page language="VB" Debug="false" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<HTML>
<script language="vbscript" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  If Not Page.IsPostBack then
    Dim strConn as string = "server=NOMEDATABASESERVER;uid=USERID;
        pwd=PASSWORD;database=NOMEDATABASE"
    Dim MySQL as string = "Select LastName from Employees"
    Dim MyConn as New SQLConnection(strConn)
    Dim objDR as SQLDataReader
    Dim Cmd as New SQLCommand(MySQL, MyConn)
    MyConn.Open()
    objDR=Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
    myDropDownList.DataSource = objDR
    myDropDownList.DataBind()
  End If
End Sub
</script>
<body>
<form Name="Form1" Runat="server">
<asp:DropDownList ID="myDropDownList" Runat="server"></asp:DropDownList>
</form>
</body>
</html>



Download Code...


Print Page


 








Page top

risorse per webmaster