why would this function return a blank page when the same code worked when in a page load method.
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-sqlclient' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Dennis West
why would this routine return a blank page when the same code worked when in a page load method. now that it is in a function it runs but does not show any datalist items on the page?? Is it because I am using a collection and need to import a namespace?

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web" %>

<html>
<head>

<script language="VB" runat="server">

Function CreateDataSource() As ICollection ' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New SqlCommand("DocumentSearch", myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim parameterSearch As SqlParameter = New SqlParameter("@Search", SqlDbType.NVarChar, 255)
parameterSearch.Value = "" 'Request.Params("txtSearch")
myCommand.Parameters.Add(parameterSearch)

' Execute the command
myConnection.Open()

DataList1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
DataList1.DataBind()
End Function

Sub Page_Load(sender As Object, e As EventArgs)

If Not IsPostBack Then
BindList
End If

End Sub

Sub BindList
DataList1.DataSource= CreateDataSource()
DataList1.DataBind
End Sub

Sub DataList_ItemCommand(sender As Object, e As DataListCommandEventArgs)
Dim cmd As String = e.CommandSource.CommandName
If cmd = "select" Then
DataList1.SelectedIndex = e.Item.ItemIndex
End If

BindList
End Sub

</script>
For 2002 ASP.NET Solutions & Articles goto:
http://aspalliance.com/dotnetsolutions/

Dennis West
West Design
MS .NET Developer
www. westontheweb.net
Click here to reveal e-mail address
Reply to this message...
 
    
William \(Bill\) Vaughn (VIP)
why would this routine return a blank page when the same code worked when in a page load method. now that it is in a function it runs but does not show any datalist items on the page?? Is it because I am using
a collection and need to import a namespace?

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web" %>

<html>
<head>

<script language="VB" runat="server">

Function CreateDataSource() As ICollection ' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New SqlCommand("DocumentSearch",
myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim parameterSearch As SqlParameter = New SqlParameter("@Search", SqlDbType.NVarChar, 255)
parameterSearch.Value = "" 'Request.Params("txtSearch")
myCommand.Parameters.Add(parameterSearch)

' Execute the command
myConnection.Open()

DataList1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
DataList1.DataBind()
End Function

Sub Page_Load(sender As Object, e As EventArgs)

If Not IsPostBack Then
BindList
End If

End Sub

Sub BindList
DataList1.DataSource= CreateDataSource()
DataList1.DataBind
End Sub

Sub DataList_ItemCommand(sender As Object, e As DataListCommandEventArgs)
Dim cmd As String = e.CommandSource.CommandName
If cmd = "select" Then
DataList1.SelectedIndex = e.Item.ItemIndex
End If

BindList
End Sub

</script>
For 2002 ASP.NET Solutions & Articles goto:
http://aspalliance.com/dotnetsolutions/

Dennis West
West Design
MS .NET Developer
www. westontheweb.net
Click here to reveal e-mail address
Reply to this message...
 
 
System.Collections.ICollection
System.Configuration.ConfigurationSettings
System.Data.CommandBehavior
System.Data.CommandType
System.Data.SqlClient.SqlCommand
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlParameter
System.Data.SqlDbType
System.EventArgs
System.Web.UI.WebControls.DataList
System.Web.UI.WebControls.DataListCommandEventArgs




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com