tcalbaz
asked on
Databinding to a simple form.
Hello,
I come from a classic ASP background. I understand the general principles of ASP.Net but I hit a brick wall when it comes to databinding. It seems many other would be asp.net people are in the same boat as me.
I am trying to solve this stumbling block by working with an example based on a simple asp.net 1.1 Framework web form.
All of the tutorials I've seen on the Net (and msdn) so far seem to want you to use a datagrid, listbox or repeater. I would prefer not to use them at all.
Based on this simple scenario can someone lay it out for me?
Here's what I got:
-------------------------- ---------- ---------- ---------- ---------- ---------- --------
I am using the SQL Server Northwinds Sample Database with the 'Orders' Table
On my Webform I have a single textbox1 (for now) that is to contain the Orders table field called: Shipname.
I have a SQLAdapter1, a SQLConnector1 and a Dataset1 based on from 'SELECT * FROM ORDERS'
My goals are:
1. Bind the single field 'Shipname' in the Orders Table to textbox1.
2. Create navigate buttons that go to First, Prev, Next, Last, Save/Update, and Create a new Record.
What do I need to do to make this work?
Once I have this I can move on.
Thank you!
Ted
I come from a classic ASP background. I understand the general principles of ASP.Net but I hit a brick wall when it comes to databinding. It seems many other would be asp.net people are in the same boat as me.
I am trying to solve this stumbling block by working with an example based on a simple asp.net 1.1 Framework web form.
All of the tutorials I've seen on the Net (and msdn) so far seem to want you to use a datagrid, listbox or repeater. I would prefer not to use them at all.
Based on this simple scenario can someone lay it out for me?
Here's what I got:
--------------------------
I am using the SQL Server Northwinds Sample Database with the 'Orders' Table
On my Webform I have a single textbox1 (for now) that is to contain the Orders table field called: Shipname.
I have a SQLAdapter1, a SQLConnector1 and a Dataset1 based on from 'SELECT * FROM ORDERS'
My goals are:
1. Bind the single field 'Shipname' in the Orders Table to textbox1.
2. Create navigate buttons that go to First, Prev, Next, Last, Save/Update, and Create a new Record.
What do I need to do to make this work?
Once I have this I can move on.
Thank you!
Ted
ASKER
Aeros,
Thanks for the quick reply. But I am attempting to create a form that does not use datagrids, repeaters or datalist:
".... All of the tutorials I've seen on the Net (and msdn) so far seem to want you to use a datagrid, listbox or repeater. I would prefer not to use them at all......"
Do you have an example for just a simple form using a single textbox?
Thank You
Ted
Thanks for the quick reply. But I am attempting to create a form that does not use datagrids, repeaters or datalist:
".... All of the tutorials I've seen on the Net (and msdn) so far seem to want you to use a datagrid, listbox or repeater. I would prefer not to use them at all......"
Do you have an example for just a simple form using a single textbox?
Thank You
Ted
Here ya go with validation of course:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="EditJob.aspx.v b" Inherits="Synthesis.EditJo b"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>EditJob</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScri pt" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="FlowLayout ">
<form id="Form1" method="post" runat="server">
<P>
<asp:Label id="Label1" runat="server" Font-Size="Large" Font-Bold="True" ForeColor="#4980B9">Edit existing job</asp:Label>
<asp:Label id="lblJobNumberID" runat="server" Visible="False">JobNumberI D</asp:Lab el>
<HR width="100%" SIZE="1">
<P></P>
<P>
<TABLE id="Table1" style="WIDTH: 481px; HEIGHT: 146px" cellSpacing="1" cellPadding="1"
width="481" border="1">
<TR>
<TD>
<asp:Label id="Label2" runat="server" Font-Bold="True" Width="160px">Job Number:</asp:Label></TD>
<TD>
<asp:Label id="lblJobNumber" runat="server">JobNumber</ asp:Label> </TD>
</TR>
<TR>
<TD>
<asp:Label id="Label3" runat="server" Font-Bold="True">CustomerI D</asp:Lab el></TD>
<TD>
<asp:TextBox id="txtCustomerID" runat="server" Width="304px"></asp:TextBo x></TD>
</TR>
<TR>
<TD>
<asp:Label id="Label4" runat="server" Font-Bold="True">StartDate (mm/dd/yyy y)</asp:La bel></TD>
<TD>
<asp:TextBox id="txtStartDate" runat="server" Width="304px"></asp:TextBo x></TD>
</TR>
<TR>
<TD>
<asp:Label id="Label5" runat="server" Font-Bold="True">EndDate(m m/dd/yyyy) </asp:Labe l></TD>
<TD>
<asp:TextBox id="txtEndDate" runat="server" Width="304px"></asp:TextBo x></TD>
</TR>
<TR>
<TD>
<asp:Label id="Label6" runat="server" Font-Bold="True">AssignedS taff</asp: Label></TD >
<TD>
<asp:TextBox id="txtAssignedStaff" runat="server" Width="304px"></asp:TextBo x></TD>
</TR>
<TR>
<TD>
<asp:Label id="Label7" runat="server" Font-Bold="True">Descripti on</asp:La bel></TD>
<TD>
<asp:TextBox id="txtDescription" runat="server" Width="304px" Height="194px" TextMode="MultiLine"
MaxLength="200"></asp:Text Box></TD>
</TR>
<tr>
<td>
<asp:ValidationSummary id="ValidationSummary1" runat="server" Width="168px" Height="34px" HeaderText="Please review the following"></asp:Validatio nSummary>< /td>
<td align="right"><INPUT id="Submit1" type="submit" value="Submit" name="Submit1" runat="server"></td>
</tr>
</TABLE>
</P>
<P>
<asp:RequiredFieldValidato r id="RequiredFieldValidator 1" runat="server" ErrorMessage="CustomerID is a required field"
ControlToValidate="txtCust omerID" Display="None"></asp:Requi redFieldVa lidator>
<asp:RequiredFieldValidato r id="RequiredFieldValidator 2" runat="server" Visible="False" ErrorMessage="StartDate is a required field"
ControlToValidate="txtStar tDate" Display="None"></asp:Requi redFieldVa lidator>
<asp:RequiredFieldValidato r id="RequiredFieldValidator 3" runat="server" Visible="False" ErrorMessage="EndDate is a required field"
ControlToValidate="txtEndD ate" Display="None"></asp:Requi redFieldVa lidator></ P>
<P>
<asp:RequiredFieldValidato r id="RequiredFieldValidator 4" runat="server" Visible="False" ErrorMessage="AssignedStaf f is a required field"
ControlToValidate="txtAssi gnedStaff" Display="None"></asp:Requi redFieldVa lidator>
<asp:RequiredFieldValidato r id="RequiredFieldValidator 5" runat="server" ErrorMessage="Description is a required field"
ControlToValidate="txtDesc ription" Display="None"></asp:Requi redFieldVa lidator></ P>
</form>
</body>
</HTML>
Public Class EditJob
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls. Label
Protected WithEvents Label7 As System.Web.UI.WebControls. Label
Protected WithEvents Label6 As System.Web.UI.WebControls. Label
Protected WithEvents Label5 As System.Web.UI.WebControls. Label
Protected WithEvents Label4 As System.Web.UI.WebControls. Label
Protected WithEvents Label3 As System.Web.UI.WebControls. Label
Protected WithEvents lblJobNumber As System.Web.UI.WebControls. Label
Protected WithEvents Label2 As System.Web.UI.WebControls. Label
Protected WithEvents lblJobNumberID As System.Web.UI.WebControls. Label
Protected WithEvents txtCustomerID As System.Web.UI.WebControls. TextBox
Protected WithEvents txtStartDate As System.Web.UI.WebControls. TextBox
Protected WithEvents txtEndDate As System.Web.UI.WebControls. TextBox
Protected WithEvents txtAssignedStaff As System.Web.UI.WebControls. TextBox
Protected WithEvents txtDescription As System.Web.UI.WebControls. TextBox
Protected WithEvents Submit1 As System.Web.UI.HtmlControls .HtmlInput Button
Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls. RequiredFi eldValidat or
Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls. RequiredFi eldValidat or
Protected WithEvents RequiredFieldValidator3 As System.Web.UI.WebControls. RequiredFi eldValidat or
Protected WithEvents RequiredFieldValidator4 As System.Web.UI.WebControls. RequiredFi eldValidat or
Protected WithEvents RequiredFieldValidator5 As System.Web.UI.WebControls. RequiredFi eldValidat or
Protected WithEvents ValidationSummary1 As System.Web.UI.WebControls. Validation Summary
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara tion As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Me.lblJobNumberID.text = CInt(Request.QueryString(" jnid"))
Catch ex As Exception
Response.Redirect("ManageP roducts.as px")
End Try
If Not IsPostBack Then LoadProductData(Me.lblJobN umberID.Te xt)
End Sub
Private Sub LoadProductData(ByVal JobNumberID As Integer)
Dim cnn As New SqlClient.SqlConnection(Co nfiguratio nSettings. AppSetting s("SiteDB" ))
Dim cmd As New SqlClient.SqlCommand
Dim dr As SqlClient.SqlDataReader
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROM JobNumbers " & _
"WHERE JobNumberID = " & JobNumberID.ToString()
cmd.Connection = cnn
cnn.Open()
dr = cmd.ExecuteReader(CommandB ehavior.Cl oseConnect ion)
dr.Read()
Me.lblJobNumber.Text = CStr(dr("JobNumber"))
Me.txtCustomerID.Text = CStr(dr("CustomerID"))
Me.txtStartDate.Text = CStr(dr("StartDate"))
Me.txtEndDate.Text = CStr(dr("EndDate"))
Me.txtAssignedStaff.Text = CStr(dr("AssignedStaff"))
Me.txtDescription.Text = CStr(dr("Description"))
cnn.Close()
dr.Close()
cmd.Dispose()
cnn.Dispose()
End Sub
Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit1.ServerClick
Page.Validate()
If Me.IsValid Then
Dim cnn As New SqlClient.SqlConnection(Co nfiguratio nSettings. AppSetting s("SiteDB" ))
Dim cmd As New SqlClient.SqlCommand
cmd.CommandType = CommandType.Text
cmd.CommandText = "UPDATE Jobnumbers SET JobNumber = " & Me.lblJobNumber.Text & _
", CustomerID = " & Me.txtCustomerID.Text & ", StartDate = '" & Me.txtStartDate.Text & _
"', EndDate = '" & Me.txtEndDate.Text & "', AssignedStaff = '" & Me.txtAssignedStaff.Text & _
"', Description = '" & Me.txtDescription.Text & "' WHERE JobNumberID = " & Me.lblJobNumberID.Text
cmd.Connection = cnn
cnn.Open()
cmd.ExecuteNonQuery()
cnn.Close()
cmd.Dispose()
cnn.Dispose()
Response.Redirect("ViewJob s.aspx")
End If
End Sub
End Class
Hope that clears it up:
Regards,
Aeros
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="EditJob.aspx.v
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>EditJob</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScri
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="FlowLayout
<form id="Form1" method="post" runat="server">
<P>
<asp:Label id="Label1" runat="server" Font-Size="Large" Font-Bold="True" ForeColor="#4980B9">Edit existing job</asp:Label>
<asp:Label id="lblJobNumberID" runat="server" Visible="False">JobNumberI
<HR width="100%" SIZE="1">
<P></P>
<P>
<TABLE id="Table1" style="WIDTH: 481px; HEIGHT: 146px" cellSpacing="1" cellPadding="1"
width="481" border="1">
<TR>
<TD>
<asp:Label id="Label2" runat="server" Font-Bold="True" Width="160px">Job Number:</asp:Label></TD>
<TD>
<asp:Label id="lblJobNumber" runat="server">JobNumber</
</TR>
<TR>
<TD>
<asp:Label id="Label3" runat="server" Font-Bold="True">CustomerI
<TD>
<asp:TextBox id="txtCustomerID" runat="server" Width="304px"></asp:TextBo
</TR>
<TR>
<TD>
<asp:Label id="Label4" runat="server" Font-Bold="True">StartDate
<TD>
<asp:TextBox id="txtStartDate" runat="server" Width="304px"></asp:TextBo
</TR>
<TR>
<TD>
<asp:Label id="Label5" runat="server" Font-Bold="True">EndDate(m
<TD>
<asp:TextBox id="txtEndDate" runat="server" Width="304px"></asp:TextBo
</TR>
<TR>
<TD>
<asp:Label id="Label6" runat="server" Font-Bold="True">AssignedS
<TD>
<asp:TextBox id="txtAssignedStaff" runat="server" Width="304px"></asp:TextBo
</TR>
<TR>
<TD>
<asp:Label id="Label7" runat="server" Font-Bold="True">Descripti
<TD>
<asp:TextBox id="txtDescription" runat="server" Width="304px" Height="194px" TextMode="MultiLine"
MaxLength="200"></asp:Text
</TR>
<tr>
<td>
<asp:ValidationSummary id="ValidationSummary1" runat="server" Width="168px" Height="34px" HeaderText="Please review the following"></asp:Validatio
<td align="right"><INPUT id="Submit1" type="submit" value="Submit" name="Submit1" runat="server"></td>
</tr>
</TABLE>
</P>
<P>
<asp:RequiredFieldValidato
ControlToValidate="txtCust
<asp:RequiredFieldValidato
ControlToValidate="txtStar
<asp:RequiredFieldValidato
ControlToValidate="txtEndD
<P>
<asp:RequiredFieldValidato
ControlToValidate="txtAssi
<asp:RequiredFieldValidato
ControlToValidate="txtDesc
</form>
</body>
</HTML>
Public Class EditJob
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg
End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.
Protected WithEvents Label7 As System.Web.UI.WebControls.
Protected WithEvents Label6 As System.Web.UI.WebControls.
Protected WithEvents Label5 As System.Web.UI.WebControls.
Protected WithEvents Label4 As System.Web.UI.WebControls.
Protected WithEvents Label3 As System.Web.UI.WebControls.
Protected WithEvents lblJobNumber As System.Web.UI.WebControls.
Protected WithEvents Label2 As System.Web.UI.WebControls.
Protected WithEvents lblJobNumberID As System.Web.UI.WebControls.
Protected WithEvents txtCustomerID As System.Web.UI.WebControls.
Protected WithEvents txtStartDate As System.Web.UI.WebControls.
Protected WithEvents txtEndDate As System.Web.UI.WebControls.
Protected WithEvents txtAssignedStaff As System.Web.UI.WebControls.
Protected WithEvents txtDescription As System.Web.UI.WebControls.
Protected WithEvents Submit1 As System.Web.UI.HtmlControls
Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.
Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.
Protected WithEvents RequiredFieldValidator3 As System.Web.UI.WebControls.
Protected WithEvents RequiredFieldValidator4 As System.Web.UI.WebControls.
Protected WithEvents RequiredFieldValidator5 As System.Web.UI.WebControls.
Protected WithEvents ValidationSummary1 As System.Web.UI.WebControls.
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Me.lblJobNumberID.text = CInt(Request.QueryString("
Catch ex As Exception
Response.Redirect("ManageP
End Try
If Not IsPostBack Then LoadProductData(Me.lblJobN
End Sub
Private Sub LoadProductData(ByVal JobNumberID As Integer)
Dim cnn As New SqlClient.SqlConnection(Co
Dim cmd As New SqlClient.SqlCommand
Dim dr As SqlClient.SqlDataReader
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROM JobNumbers " & _
"WHERE JobNumberID = " & JobNumberID.ToString()
cmd.Connection = cnn
cnn.Open()
dr = cmd.ExecuteReader(CommandB
dr.Read()
Me.lblJobNumber.Text = CStr(dr("JobNumber"))
Me.txtCustomerID.Text = CStr(dr("CustomerID"))
Me.txtStartDate.Text = CStr(dr("StartDate"))
Me.txtEndDate.Text = CStr(dr("EndDate"))
Me.txtAssignedStaff.Text = CStr(dr("AssignedStaff"))
Me.txtDescription.Text = CStr(dr("Description"))
cnn.Close()
dr.Close()
cmd.Dispose()
cnn.Dispose()
End Sub
Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit1.ServerClick
Page.Validate()
If Me.IsValid Then
Dim cnn As New SqlClient.SqlConnection(Co
Dim cmd As New SqlClient.SqlCommand
cmd.CommandType = CommandType.Text
cmd.CommandText = "UPDATE Jobnumbers SET JobNumber = " & Me.lblJobNumber.Text & _
", CustomerID = " & Me.txtCustomerID.Text & ", StartDate = '" & Me.txtStartDate.Text & _
"', EndDate = '" & Me.txtEndDate.Text & "', AssignedStaff = '" & Me.txtAssignedStaff.Text & _
"', Description = '" & Me.txtDescription.Text & "' WHERE JobNumberID = " & Me.lblJobNumberID.Text
cmd.Connection = cnn
cnn.Open()
cmd.ExecuteNonQuery()
cnn.Close()
cmd.Dispose()
cnn.Dispose()
Response.Redirect("ViewJob
End If
End Sub
End Class
Hope that clears it up:
Regards,
Aeros
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Fribble1,
I think we're on the same wavelength : )
Yes, it is true that I will be returning multiple records so I will probally need the dataset and dataadapter. I also intend to eventually expand to many fields on my form.
And as you surmised I will definitely be needing a means to navigate through records with First:Prev:Next:Last and then a means to Save/Update and Add/Delete records.
So I will be patient and wait until you have a chance to illustrate those too.
I am using a simple model like this so that I can grasp all of the concepts
Thank You,
Ted
.
I think we're on the same wavelength : )
Yes, it is true that I will be returning multiple records so I will probally need the dataset and dataadapter. I also intend to eventually expand to many fields on my form.
And as you surmised I will definitely be needing a means to navigate through records with First:Prev:Next:Last and then a means to Save/Update and Add/Delete records.
So I will be patient and wait until you have a chance to illustrate those too.
I am using a simple model like this so that I can grasp all of the concepts
Thank You,
Ted
.
ASKER
Valuable Tips,
Thank you Fribble!
Ted
Thank you Fribble!
Ted
Sorry i haven't got back to you for a while have been very busie at work and din't relly feel like looking at more code when i got home. Are yoiu still haveing problems getting a a forward and back button working?
Public Class ViewJobs
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg
End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.
Protected WithEvents dg As System.Web.UI.WebControls.
Protected WithEvents SearchProducts As System.Web.UI.WebControls.
Protected WithEvents FieldsToMatch As System.Web.UI.WebControls.
Protected WithEvents SearchQuery As System.Web.UI.WebControls.
Protected WithEvents FullQuery As System.Web.UI.HtmlControls
Protected WithEvents Label2 As System.Web.UI.WebControls.
Protected WithEvents Label3 As System.Web.UI.WebControls.
Protected WithEvents Label4 As System.Web.UI.WebControls.
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
BindTheData()
End Sub
Private Sub BindTheData(Optional ByVal Query As String = "")
Dim cnn As New SqlClient.SqlConnection(Co
Dim cmd As New SqlClient.SqlCommand
Dim da As New SqlClient.SqlDataAdapter(c
Dim ds As New DataSet
If Query = "" Then Query = FullQuery.Value
If Query = "" Then
Query = "SELECT * FROM JobNumbers ORDER BY JobNumber DESC"
End If
cmd.CommandText = Query
cmd.Connection = cnn
cnn.Open()
da.SelectCommand = cmd
da.Fill(ds, "JobNumbers")
dg.DataSource = ds.Tables("JobNumbers").De
dg.DataKeyField = "JobNumberID"
dg.DataBind()
cnn.Close()
cmd.Dispose()
cnn.Dispose()
End Sub
Private Sub dg_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.
dg.CurrentPageIndex = e.NewPageIndex
Dim Query As String
Query = "SELECT * FROM JobNumbers WHERE JobNumbers."
Select Case FieldsToMatch.SelectedValu
Case "JobNumber"
Query &= "JobNumber LIKE '%" & SearchQuery.Text & "%'"
Case "CustomerID"
Query &= "CustomerID LIKE '%" & SearchQuery.Text & "%'"
Case "Either"
Query &= "JobNumber LIKE '%" & SearchQuery.Text & "%' " & _
"OR JobNumber.CustomerID LIKE '%" & SearchQuery.Text & "%'"
End Select
Query &= " ORDER BY JobNumbers.JobNumberID DESC"
BindTheData(Query)
FullQuery.Value = Query
End Sub
Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.
If e.CommandName = "Edit" Then
Response.Redirect("EditJob
End If
End Sub
Private Sub SearchProducts_Click(ByVal
Dim Query As String
Query = "SELECT * FROM JobNumbers WHERE JobNumbers."
Select Case FieldsToMatch.SelectedValu
Case "JobNumber"
Query &= "JobNumber LIKE '%" & SearchQuery.Text & "%'"
Case "CustomerID"
Query &= "CustomerID LIKE '%" & SearchQuery.Text & "%'"
Case "Either"
Query &= "JobNumber LIKE '%" & SearchQuery.Text & "%' " & _
"OR JobNumber.CustomerID LIKE '%" & SearchQuery.Text & "%'"
End Select
Query &= " ORDER BY JobNumbers.JobNumberID DESC"
BindTheData(Query)
FullQuery.Value = Query
End Sub
End Class
For a clickable Datalist With Custom Paging:
<%@ Page language="vb" Inherits="DOTNETShoppingCa
<HTML>
<HEAD>
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<style>
.GridHeader TD { PADDING-RIGHT: 20px; FONT-WEIGHT: bold; BORDER-BOTTOM: black 2px solid; WHITE-SPACE: nowrap }
.GridItem TD { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-WEIGHT: normal; PADDING-BOTTOM: 5px; CURSOR: hand; PADDING-TOP: 5px; BORDER-BOTTOM: white 1px solid; FONT-FAMILY: Courier New; WHITE-SPACE: nowrap; BACKGROUND-COLOR: #ffffff; asp: Literal id="ItemLetterSpacing" runat="server"></asp:Liter
.GridItemAlternate TD { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-WEIGHT: normal; PADDING-BOTTOM: 5px; CURSOR: hand; PADDING-TOP: 5px; BORDER-BOTTOM: white 1px solid; FONT-FAMILY: Courier New; WHITE-SPACE: nowrap; BACKGROUND-COLOR: #f3f3f3; asp: Literal id="AltItemLetterSpacing" runat="server"></asp:Liter
.GridItemOver TD { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 5px; CURSOR: hand; PADDING-TOP: 5px; FONT-FAMILY: Courier New; WHITE-SPACE: nowrap; BACKGROUND-COLOR: #fffdce }
.GridItemInactive TD { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-WEIGHT: normal; PADDING-BOTTOM: 5px; CURSOR: hand; PADDING-TOP: 5px; BORDER-BOTTOM: white 1px solid; FONT-FAMILY: Courier New; WHITE-SPACE: nowrap; BACKGROUND-COLOR: #d5dbe1; asp: Literal id="InactiveItemLetterSpac
</style>
<script language="javascript">
<!--
function openLocation(newlocation) {
if (newlocation.length != 0)
window.location = newlocation;
else
return;
}
//-->
</script>
</HEAD>
<body>
<form runat="server">
<h3>
<H3><asp:datalist id="dtlProducts" runat="server" Width="738px" RepeatColumns="1" DataKeyField="ProductID">
<HeaderTemplate>
<table width="100%" cellspacing="0" cellpadding="0">
<tr class="Gridheader">
<th align="left" width="15%">
Image</th>
<th align="left" width="25%">
Product Name</th>
<th align="left" width="45%">
Description</th>
<th align="left" width="15%">
Price</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr id="ItemRow" runat="server" class="GridItem" onmouseover="this.classNam
onmouseout="this.className
<td><img src='<%# DataBinder.Eval(Container.
<td><%# DataBinder.Eval(Container.
<td><%# DataBinder.Eval(Container.
<td><%# DataBinder.Eval(Container.
</tr>
</ItemTemplate>
</asp:datalist></H3>
</h3>
<table width="100%">
<tr>
<td align="left" width="42%"><asp:label id="lblCounts" Runat="server" CssClass="plaintable"></as
<TD vAlign="bottom" width="4%"><A id="First" href="pagingdatalist.aspx#
</TD>
<TD vAlign="bottom" width="4%"><A id="Previous" href="pagingdatalist.aspx#
</TD>
<TD vAlign="bottom" width="4%"><A id="Next" href="pagingdatalist.aspx#
</TD>
<TD vAlign="bottom" width="4%"><A id="Last" href="pagingdatalist.aspx#
</TD>
<TD width="42%"> </TD>
</tr>
</table>
<asp:label id="lblRecordCount" Runat="server" Visible="False"></asp:labe
<H3> </H3>
</form>
</body>
</HTML>
Imports System.Data
Imports System.Data.OleDb
Imports System.Configuration
Public Class PagingDataList : Inherits System.Web.UI.Page
Protected WithEvents First As System.Web.UI.HtmlControls
Protected WithEvents Previous As System.Web.UI.HtmlControls
Protected WithEvents dtlProducts As System.Web.UI.WebControls.
Protected WithEvents lblCounts As System.Web.UI.WebControls.
Protected WithEvents lblRecordCount As System.Web.UI.WebControls.
Protected WithEvents lblCurrentIndex As System.Web.UI.WebControls.
Protected WithEvents lblPageSize As System.Web.UI.WebControls.
Protected WithEvents Last As System.Web.UI.HtmlControls
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack() Then
BindTheData()
End If
End Sub
Private Sub BindTheData()
Dim cnn As New OleDb.OleDbConnection(Conf
Dim DataAdapter As New OleDb.OleDbDataAdapter("SE
Dim DataSet As New DataSet
Dim PageSize As Integer = 10
cnn.Open()
If Not Page.IsPostBack() Then
DataAdapter.Fill(DataSet)
lblRecordCount.Text = CStr(DataSet.Tables(0).Row
DataSet = Nothing
DataSet = New DataSet
End If
DataAdapter.Fill(DataSet, CInt(lblCurrentIndex.Text)
dtlProducts.DataSource = DataSet.Tables("Products")
dtlProducts.DataBind()
cnn.Close()
ShowCounts()
cnn.Dispose()
DataAdapter.Dispose()
End Sub
Public Sub ShowFirstPage(ByVal s As System.Object, ByVal e As System.EventArgs)
lblCurrentIndex.Text = "0"
BindTheData()
End Sub
Public Sub ShowPreviousPage(ByVal s As System.Object, ByVal e As System.EventArgs)
lblCurrentIndex.Text = CStr(CInt(lblCurrentIndex.
If CInt(lblCurrentIndex.Text)
lblCurrentIndex.Text = "0"
End If
BindTheData()
End Sub
Public Sub ShowNextPage(ByVal s As System.Object, ByVal e As System.EventArgs)
If CInt(CInt(lblCurrentIndex.
lblCurrentIndex.Text = CStr(CInt(lblCurrentIndex.
End If
BindTheData()
End Sub
Public Sub ShowLastPage(ByVal s As System.Object, ByVal e As System.EventArgs)
Dim intMod As Integer
intMod = CInt(lblRecordCount.Text) Mod CInt(lblPageSize.Text)
If intMod > 0 Then
lblCurrentIndex.Text = CStr(CInt(lblRecordCount.T
Else
lblCurrentIndex.Text = CStr(CInt(lblRecordCount.T
End If
BindTheData()
End Sub
Private Sub ShowCounts()
lblCounts.Text = "|Total Rows: <b>" & lblRecordCount.Text
lblCounts.Text += "</b> | Page:<b> "
lblCounts.Text += CStr(CInt(CInt(lblCurrentI
lblCounts.Text += "</b> of <b>"
If (CInt(lblRecordCount.Text)
lblCounts.Text += CStr(CInt(CInt(lblRecordCo
Else
lblCounts.Text += CStr(CInt(lblRecordCount.T
End If
lblCounts.Text += "</b> |"
End Sub
Private Sub InitializeComponent()
End Sub
Private Sub dtlProducts_ItemDataBound(
Dim TR As HtmlTableRow
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingIt
TR = CType(e.Item.FindControl("
If e.Item.ItemType = ListItemType.AlternatingIt
TR.Attributes("onmouseout"
TR.Attributes("class") = "GridItemAlternate"
End If
If CStr(DataBinder.Eval(e.Ite
TR.Attributes("class") = "GridItemInactive"
TR.Attributes("onmouseout"
End If
End If
End Sub
Private Sub dtlProducts_SelectedIndexC
End Sub
End Class
If you need the .aspx code for the standard datagrid let me know, but Its just that standard, you can drag and drop it.
Regards,
Aeros