.NETGURU
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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification