ASP.NET Code
  Home arrow ASP.NET Code arrow ASP.NET [ OPINION POLLS ]
Click Here
Iron Speed
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 / 92
    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

    AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    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!


    Be the first to hear about i5/OS V6R1!

    Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br />
    FREE! Go There Now!


    IBM – Taking Web 2.0 to Work

    You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David 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! Hacking 101

    Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today.
    FREE! Go There Now!


    NEW! Harnessing the power of SQL and Java for high performance data access

    Join this webcast to see how IBM Data Studio Developer and pureQuery can take the pain out of Java data access. uApplications developed using both Java and SQL have become a common requirement. Database connectivity using Java Database Connectivity (JDBC) to create an application is a multi-step tedious process, and tooling that covers both SQL and Java has been unavailable, until now. IBM Data Studio introduces the pureQuery platform: a high-performance, Java data access platform focused on simplifying the tasks of developing, managing, and optimizing database applications and services.
    FREE! Go There Now!


    NEW! IBM Rational AppScan Standard Edition V7.7

    Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7.
    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' Teleconference Series

    This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today!
    FREE! Go There Now!


    NEW! Rational Asset Manager eKit

    Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions.
    FREE! Go There Now!


    NEW! Rational Modeling Extension for Microsoft.Net

    Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms.
    FREE! Go There Now!


    NEW! Webcast: Extreme transaction processing with WebSphere Extended Deployment

    In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications.
    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-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway