Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 12th, 2004, 04:07 PM
ricksterval's Avatar
ricksterval ricksterval is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 31 ricksterval User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Asp.net [ Opinion Polls ]

<!%@ Page Language="vb" Explicit="true" Debug="true" %>
<!%@ Import Namespace="System.Text" %>
<!%@ import Namespace="System.Data" %>
<!%@ import Namespace="Sys ...A Very Simple but usefull ASP.NET Opinion poll example.

Create a folder called polls in your "c:/Inetpub/wwwroot"

open your web browser and type "http://localhost/polls/Default.aspx".

Put all the files listed below in the folder listed above.

[bold]Default.aspx[/bold]
[code]
<%@ Page Language="vb" Explicit="true" Debug="true" %>
<%@ Import Namespace="System.Text" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<html>
<head>
<meta name="GENERATOR" Content="ASP Express 2.1">
<title>J.Ramkrshna Murty - [ASP.NET Opinion Polls - Ver1.0]</title>
<script language="VB" runat="server">
Sub Page_Change(sender As Object, e As DataGridPageChangedEventArgs)
MyDataGrid.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
Sub Page_Load(Source As Object, E As EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
If Page.IsPostBack Then
End If
End Sub
Sub BindData()
'1. Create a connection
Dim objConn
objConn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("polls.mdb") & ";")
objConn.Open
'2. Create a command object for the query
Const strSQL as String = "select * from polls where currentquestion=0"
Dim objCmd as New OleDbCommand(strSQL, objConn)
'3. Create/Populate the DataReader
Dim objDR as OleDbDataReader
objDR = objCmd.ExecuteReader()
MyDataGrid.DataSource = objDR
MyDataGrid.DataBind()
End Sub
</script>
</head>
<body>
<div id=divResults runat=server />
<aspatagrid runat="server"
Id="MyDataGrid"
GridLines="Both"
cellpadding="0"
cellspacing="0"
BorderWidth="0"
Headerstyle-BackColor="white"
Headerstyle-Font-Name="Arial"
Headerstyle-Font-Bold="True"
Headerstyle-Font-Size="14"
BackColor="white"
Font-Name="Arial"
Font-Size="11"
AlternatingItemStyle-BackColor="white"
AlternatingItemStyle-Font-Name="Arial"
AlternatingItemStyle-Font-Size="11"
BorderColor="white"
AllowPaging = "false"
AllowCustomPaging ="false"
PageSize = "8"
PagerStyle-Mode = "NumericPages"
PagerStyle-HorizontalAlign="Center"
PagerStyle-PageButtonCount = "10"
OnPageIndexChanged = "Page_Change"
AutogenerateColumns="False"
Width="50%">
<Columns>
<asp:TemplateColumn HeaderText="">
<ItemTemplate>
<form action="results.aspx" id="sample1" method="get">
<table bgcolor="#FFFFFF" cellspacing="1" border="2" cellpadding="4">
<tr>
<td width="384" bordercolor="#FF9900" bgcolor="#FF9900"> <div align="center"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">ASP.NET
- Opinion Polls - Ver1.0</font></strong></div></td>
</tr>
<tr><td>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td colspan="2"> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%# DataBinder.Eval(Container.DataItem, "question") %>
</font></td>
</tr>
<tr>
<td width="11%">

<input type="hidden" name="pollid" id="pollid" value="<%# DataBinder.Eval(Container.DataItem, "currentquestion") %>">
<input type="radio" name="choice" value="Choice1,<%# DataBinder.Eval(Container.DataItem, "votes1")%>"></td>
<td width="89%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%# DataBinder.Eval(Container.DataItem, "choice1") %>
</font></td>
</tr>
<tr>
<td><input type="radio" name="choice" value="Choice2,<%# DataBinder.Eval(Container.DataItem, "votes2")%>"></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%# DataBinder.Eval(Container.DataItem, "choice2") %>
</font></td>
</tr>
<tr>
<td><input type="radio" name="choice" value="Choice3,<%# DataBinder.Eval(Container.DataItem, "votes3")%>"></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%# DataBinder.Eval(Container.DataItem, "choice3") %>
</font></td>
</tr>
<tr>
<td><input type="radio" name="choice" value="Choice4,<%# DataBinder.Eval(Container.DataItem, "votes4")%>"></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%# DataBinder.Eval(Container.DataItem, "choice4") %>
</font><input type="submit" id=submit value="Vote"></td>
</tr>
</table>

</td></tr>
</table>
</form>

</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</aspataGrid>
</body>
</html>



[bold]results.aspx[/bold]

<%@ Page Language="vb" Explicit="true" Debug="true"%>
<%@ Import Namespace="System.Text" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<html>
<head>
<meta name="GENERATOR" Content="ASP Express 2.1">
<title>J.Ramkrshna Murty - [ASP.NET Opinion Polls - Ver1.0]</title>
<script language="VB" runat="server">

Sub Page_Change(sender As Object, e As DataGridPageChangedEventArgs)
BindData()
End Sub

Sub Page_Load(Source As Object, E As EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub

Sub BindData()
'1. Create a connection
Dim objConn
objConn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("polls.mdb") & ";")

'You must open the db connection before populating the DataReader

objConn.Open()
Dim strSQL as String
strSQL="select * from polls where currentquestion="& Request.querystring("pollid")
Dim objCmd as New OleDbCommand(strSQL, objConn)

'3. Create/Populate the DataReader

Dim objDR as OleDbDataReader
objDR = objCmd.ExecuteReader()
MyDataGrid.DataSource = objDR
MyDataGrid.DataBind()

'4.Updating Polls
'5. Create a New connection

Dim objConn1
objConn1=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("polls.mdb") & ";")

Dim votevalue
Dim ChoiceValue
Dim VotedFor
ChoiceValue=(left(request.QueryString("choice"),7))
if choiceValue="Choice1" then
VotedFor="Votes1"
else if choiceValue="Choice2" then
VotedFor="Votes2"
else if choiceValue="Choice3" then
VotedFor="Votes3"
else if choiceValue="Choice4" then
VotedFor="Votes4"
end if

votevalue=(Cint(right(request.QueryString("choice"),(len(request.QueryString("choice"))-8)))+1)

'2. Create the command object, passing in the SQL string

Dim strSQL1 as String = "update polls set "& VotedFor &"=" & votevalue+1 & " where currentquestion="& Request.querystring("pollid") & ""
Dim myCommand as New OleDbCommand(strSQL1, objConn1)
objConn1.Open()
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)

End Sub
</script>
</head>
<body>
<div id=divResults runat=server />
<aspatagrid runat="server"
Id="MyDataGrid"
GridLines="Both"
cellpadding="0"
cellspacing="0"
BorderWidth="0"
Headerstyle-BackColor="white"
Headerstyle-Font-Name="Arial"
Headerstyle-Font-Bold="True"
Headerstyle-Font-Size="14"
BackColor="white"
Font-Name="Arial"
Font-Size="11"
AlternatingItemStyle-BackColor="white"
AlternatingItemStyle-Font-Name="Arial"
AlternatingItemStyle-Font-Size="11"
BorderColor="white"
AllowPaging = "false"
AllowCustomPaging ="false"
PageSize = "8"
PagerStyle-Mode = "NumericPages"
PagerStyle-HorizontalAlign="Center"
PagerStyle-PageButtonCount = "10"
OnPageIndexChanged = "Page_Change"
AutogenerateColumns="False"
Width="50%">
<Columns>
<asp:TemplateColumn HeaderText="">
<ItemTemplate>
<table bgcolor="#FFFFFF" cellspacing="1" border="2" cellpadding="4">
<tr>
<td width="384" bordercolor="#FF9900" bgcolor="#FF9900"> <div align="center">ASP.NET
- Opinion Polls - Ver1.0</div></td>
</tr>
<tr><td>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="72%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%# DataBinder.Eval(Container.DataItem, "choice1")%>
</font></td>
<td width="28%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%#Cint(DataBinder.Eval(Container.DataItem, "votes1")/(DataBinder.Eval(Container.DataItem, "votes1")+DataBinder.Eval(Container.DataItem, "votes2")+DataBinder.Eval(Container.DataItem, "votes3")+DataBinder.Eval(Container.DataItem, "votes4"))*100)%>
% </font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%# DataBinder.Eval(Container.DataItem, "choice2")%>
</font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%#Cint(DataBinder.Eval(Container.DataItem, "votes2")/(DataBinder.Eval(Container.DataItem, "votes1")+DataBinder.Eval(Container.DataItem, "votes2")+DataBinder.Eval(Container.DataItem, "votes3")+DataBinder.Eval(Container.DataItem, "votes4"))*100)%>
% </font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%# DataBinder.Eval(Container.DataItem, "choice3")%>
</font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%# Cint(DataBinder.Eval(Container.DataItem, "votes3")/(DataBinder.Eval(Container.DataItem, "votes1")+DataBinder.Eval(Container.DataItem, "votes2")+DataBinder.Eval(Container.DataItem, "votes3")+DataBinder.Eval(Container.DataItem, "votes4"))*100)%>
% </font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%# DataBinder.Eval(Container.DataItem, "choice4")%>
</font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%# Cint(DataBinder.Eval(Container.DataItem, "votes4")/(DataBinder.Eval(Container.DataItem, "votes1")+DataBinder.Eval(Container.DataItem, "votes2")+DataBinder.Eval(Container.DataItem, "votes3")+DataBinder.Eval(Container.DataItem, "votes4"))*100)%>
% </font></td>
</tr>
</table>

</td></tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</aspataGrid>
</body>
</html>


Read Complete Article

Reply With Quote
  #2  
Old November 24th, 2004, 11:27 PM
mbarben mbarben is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 1 mbarben User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The Code dont work

Well strickly speaking yes it does work, however it does not have the ability to handle zeros in the database, it increments the database by multiples of two, it also does not display the data that has been entered, on the previous information

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Asp.net [ Opinion Polls ]


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT