Hi,
Ive tried to put my datagrid in a usercontrol/codebehind file but it just doesnt seem to work.
It worked fine in a standard aspx file but putting it into a codebehind seems more complicated.
Any good tutorials in VB on this?
This is where im at, there are no errors on the code but the Datagrid doesnt even show up.
I know that the aspx and ascx pages are linked properlly because if i put in some errors on purpose ASP.NET reports them.
secdesc.ascx:
codebehind secdesc.vb:
Any help would be great thanks!
Ive tried to put my datagrid in a usercontrol/codebehind file but it just doesnt seem to work.
It worked fine in a standard aspx file but putting it into a codebehind seems more complicated.
Any good tutorials in VB on this?
This is where im at, there are no errors on the code but the Datagrid doesnt even show up.
I know that the aspx and ascx pages are linked properlly because if i put in some errors on purpose ASP.NET reports them.
secdesc.ascx:
PHP:
<%@ Control Language="VB" SRC="bll/secdesc.vb"%>
<asp:datagrid ShowHeader="False" GridLines="None" id="index_sections" runat="server" EnableViewState="true" AutoGenerateColumns="false">
<columns>
<asp:templatecolumn>
<itemTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr valign="top">
<td width="50" align="top">
<img src="<%# container.dataitem( "image") %>" align="top"></td>
<td ><a href="<%# container.dataitem( "titleLink")%>">
<%# container.dataitem( "title")%>
</a> <br>
<%# container.dataitem( "article") %>
</td>
</tr>
</table>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
codebehind secdesc.vb:
PHP:
Imports System
Imports System.Configuration
Imports System.DateTime
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.DBNull
Imports System.Web
Imports System.Web.Security
Imports System.Web.SessionState
Imports System.Web.HttpServerUtility
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.Datagrid
Imports System.Web.UI.HtmlControls
namespace CMS
Public Class ModSectionDesc
Inherits System.Web.UI.UserControl
'======================
'Web controls
'======================
Protected WithEvents index_sections As System.Web.UI.WebControls.Datagrid
'======================
'Propertys (set/get)
'======================
'======================
'Subroutines
'======================
Public Sub Page_Load(ByVal sender as System.Object,ByVal e as System.EventArgs)
BindData()
End Sub
Public Sub BindData()
dim isSecure as String
'checks if the site uses http:// or https:// so we can build up our where condition in the SQL Stored Procedure
If Request.ServerVariables("HTTPS") = "off" Then
isSecure = "http://"
Else
isSecure = "https://"
End if
'SQL Stored Proc to get the modules for this appropriate site/page.
Dim conn as New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("connectionString"))
'Create new command object and query the database. Open the connection.
Dim myCommand As SqlCommand = New SqlCommand("sp_getmoddesc", conn)
myCommand.CommandType = CommandType.StoredProcedure
conn.open()
'Set up parameter for stored procedure
Dim prmRootPath As New SqlParameter()
Dim prmPagePath As New SqlParameter()
'parameters
prmRootPath.ParameterName = "@rootpath"
prmPagePath.ParameterName = "@pagepath"
prmRootPath.Value = isSecure & Request.ServerVariables("HTTP_HOST")
prmPagePath.Value = Request.ServerVariables("PATH_INFO")
'add the parameter to the command
myCommand.Parameters.Add(prmRootPath)
myCommand.Parameters.Add(prmPagePath)
index_sections.DataSource = myCommand.ExecuteReader()
index_sections.DataBind
conn.close()
End Sub
End Class
End namespace
Any help would be great thanks!