ASP.NET Code
  Home arrow ASP.NET Code arrow ASP.NET [ OPINION POLLS ]
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET CODE

ASP.NET [ OPINION POLLS ]
By: J.Ramkrishna Murty
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 99
    2003-02-02

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    A Very Simple but usefull ASP.NET Opinion poll example. Create a folder called polls in your "c:/Inetpub/wwwroot" and to test the polls 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] <!%@ import Namespace="Sys ...J.Ramkrshna Murty - [ASP.NET Opinion Polls - Ver1.0]

    Default.aspx

     
    <!--aspPage Language="vb" Explicit="true" Debug="true" -->
    <!--
    aspImport Namespace="System.Text" -->
    <!--
    aspimport Namespace="System.Data" -->
    <!--
    aspimport Namespace="System.Data.OleDb" -->
    <
    script language="VB" runat="server">
    Sub Page_Change(sender As ObjectAs 
    DataGridPageChangedEventArgs)
    MyDataGrid.CurrentPageIndex e.NewPageIndex
    BindData
    ()
    End Sub
    Sub Page_Load
    (Source As ObjectAs 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(strSQLobjConn)
    '
    3. Create/Populate the DataReader
    Dim objDR as OleDbDataReader
    objDR = objCmd.ExecuteReader()
    MyDataGrid.DataSource = objDR
    MyDataGrid.DataBind()
    End Sub
    </script></p>
    <datagrid id="MyDataGrid" width="50%" runat="server" 
    cellspacing="0" cellpadding="0" gridlines="Both" 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" />
    <columns />
    <templatecolumn />
    <itemtemplate />
    <div runat="server">
    <form id="sample1" action="results.aspx" method="get">
    <table cellspacing="1" cellpadding="4" bgcolor="#ffffff" border="2">
    <tbody>
    <tr>
    <td bordercolor="#ff9900" width="384" bgcolor="#ff9900">
    <div align="center"><strong><font face="Verdana, Arial, Helvetica, sans-serif" 
    color="#ffffff" size="2">ASP.NET - Opinion Polls - Ver1.0</font>
    </strong></div></td></tr>
    <tr>
    <td>
    <table cellspacing="0" cellpadding="5" width="100%" border="0">
    <tbody>
    <tr>
    <td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif" 
    size="2">
    <!--asp# DataBinder.Eval(Container.DataItem, "question") -->
    </font></td></tr>
    <tr>
    <td width="11%">
    <input id="pollid" type="hidden" 
    value="<!--asp# DataBinder.Eval(Container.DataItem, " 
    name="pollid" />">
    <input type="radio" 
    value="Choice1,<!--asp# DataBinder.Eval(Container.DataItem, " 
    name="choice" />"></td>
    <td width="89%">
    <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <!--asp# DataBinder.Eval(Container.DataItem, "choice1") --></font>
    </td></tr>
    <tr>
    <td>
    <input type="radio" 
    value="Choice2,<!--asp# DataBinder.Eval(Container.DataItem, " 
    name="choice" />"></td>
    <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <!--asp# DataBinder.Eval(Container.DataItem, "choice2") -->
    </font></td></tr>
    <tr>
    <td>
    <input type="radio" 
    value="Choice3,<!--asp# DataBinder.Eval(Container.DataItem, " 
    name="choice" />"></td>
    <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <!--asp# DataBinder.Eval(Container.DataItem, "choice3") -->
    </font></td></tr>
    <tr>
    <td>
    <input type="radio" 
    value="Choice4,<!--asp# DataBinder.Eval(Container.DataItem, " 
    name="choice" />"></td>
    <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <!--asp# DataBinder.Eval(Container.DataItem, "choice4") --></font>
    <input id="submit" type="submit" value="Vote" />
    </td></tr></tbody></table></td></tr></tbody></table>

    results.aspx
     

     <!--aspPage Language="vb" Explicit="true" Debug="true"-->
    <!--
    aspImport Namespace="System.Text" -->
    <!--
    aspimport Namespace="System.Data" -->
    <!--
    aspimport Namespace="System.Data.OleDb" -->
    <
    script language="VB" runat="server">

    Sub Page_Change(sender As ObjectAs DataGridPageChangedEventArgs)
    BindData()
    End Sub

    Sub Page_Load
    (Source As ObjectAs 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(strSQLobjConn)

    '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 objectpassing in the SQL string

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

    End Sub
    </script>
    </div>
    <datagrid id="MyDataGrid" width="50%" runat="server" 
    cellspacing="0" cellpadding="0" gridlines="Both" 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" />
    <columns />
    <templatecolumn />
    <itemtemplate />
    <div runat="server">
    <table cellspacing="1" cellpadding="4" bgcolor="#ffffff" border="2">
    <tbody>
    <tr>
    <td bordercolor="#ff9900" width="384" bgcolor="#ff9900">
    <div align="center"><strong>
    <font face="Verdana, Arial, Helvetica, sans-serif" color="#ffffff" 
    size="2">ASP.NET - Opinion Polls - Ver1.0</font></strong></div>
    </td></tr>
    <tr>
    <td>
    <table cellspacing="0" cellpadding="5" width="100%" border="0">
    <tbody>
    <tr>
    <td width="72%"><font face="Verdana, Arial, Helvetica, sans-serif" 
    size="2"><!--asp# DataBinder.Eval(Container.DataItem, "choice1")-->
    </font></td>
    <td width="28%"><font face="Verdana, Arial, Helvetica, sans-serif" 
    size="2">
    <!--asp#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 face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <!--asp# DataBinder.Eval(Container.DataItem, "choice2")-->
    </font></td>
    <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <!--asp#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 face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <!--asp# DataBinder.Eval(Container.DataItem, "choice3")--></font></td>
    <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <!--asp# 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 face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <!--asp# DataBinder.Eval(Container.DataItem, "choice4")--></font></td>
    <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <!--asp# 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></tbody></table>
    </td></tr></tbody></table></div>
    <div runat="server">
    </itemtemplate />
    </templatecolumn />
    </columns />
    </datagrid />

     
    polls.mdb

     

    id -------------------------------- 

    Number pollsessionid 
    --------------------- 

    Number question 
    -------------------- 

    Text polldate 
    ------------------- 

    Text choice1 
    ------------------- 

    Text choice2 
    ------------------- 

    Text choice3 
    -------------------- 

    Text choice4 
    ------------------- 

    Text votes1
    --------------------- 

    (Numbervotes2 --------------------- 

    (Numbervotes3 --------------------- 

    (Numbervotes4 --------------------- 

    (Numbercurrentquestion --------------------- (Yes/No



    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP.NET Code Articles
    More By J.Ramkrishna Murty

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! IBM – Taking Web 2.0 to Work

    David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! Download DB2 9.5 for Linux, Unix, and Windows

    Download a free trial version of IBM DB2 9.5 for Linux, UNIX, and Windows. DB2 9 is the result of a five-year development project that transformed traditional (static) database technology into an interactive data server that merges the high performance and ease of use of DB2 with the self-describing benefits of XML.
    FREE! Go There Now!


    NEW! Hello World: Monitor a simple business process using WebSphere Business Monitor V6.0.2

    This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product.
    FREE! Go There Now!


    NEW! IBM Rational Systems Development e-Kit

    As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br />
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 2: Automate builds for a real-world Tomcat project

    Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available.
    FREE! Go There Now!


    NEW! Rational Talks to You: Grady Booch on Architecture

    Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered!
    FREE! Go There Now!


    NEW! Rational Talks to You: Scott Ambler on being agile in a global development environment

    Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered!
    FREE! Go There Now!


    NEW! Software Change and Configuration Management Solution Guidelines

    This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Process

    Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly.
    FREE! Go There Now!


    NEW! Webcast: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP.NET CODE ARTICLES

    - How to Use the ListBox Control in ASP.NET 2.0
    - How to Load XML Documents in ASP.NET 2.0
    - DataGrid Code
    - ASP.NET Guestbook
    - User Controls and Client Side Scripting
    - ASP.NET Programming with Microsoft's AS...
    - ASP.NET Basics (part 3): Hard Choices
    - ASP.NET Basics (part 2): Not My Type
    - ASP.NET Basics (part 1): Nothing But .Net
    - Directory Tree Browser
    - How to get the confirmation of Yes/No from a...
    - Complete example using custom errors and wri...
    - Paging Certain # records per page .NET style
    - General Methods of formatting and Subtractin...
    - .NET LinkButton web control





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek