Click here to Skip to main content
14,736,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

i'm new to & learning the language via net references

m trying to build a code which will display the contents of a single row from a Sqldatabase to the user by using labels for each of the columns...

I'm providing the following buttons "first, last, next, previous"

What i want is, onclick of the button(eg: next) the next row should be displayed on the labels...

Another thing tht i want to do is, Keep a counter that will corresspond to the rowindex of the
i.e (i =0 for row 1 of Sqldata, i=2 for row 2....)

The problem that i'm facing is that on click of any button, the page gets reloaded due to which the implementation for i is not achieved....

The following is the code and the .vb file...

Any help would be appreciated...

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Exam.aspx.vb" Inherits="Exam" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head id="Head1"  runat="server">
    <link href="Site.css" rel ="Stylesheet" type="text/css" />
    <style type="text/css">
            height: 283px;
            width: 802px;
            width: 303px;
    <form id="form1"  runat="server">
   <div class="page">
        <div class="header">
            <div class="title">
                    FAMT's Generic Online Examination System
            <div class="clear hideSkiplink">
                <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false"   Orientation="Horizontal">
                        <asp:MenuItem NavigateUrl="~/Shome.aspx" Text="Student Home"/>

        <div class="main">
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <table style="width: 700px"  cellspacing="5" cellpadding="5" align="center" 

                    border="1" frame="border" rules="all">
            <tr align=center>
            <td colspan=2 >
                <asp:Label ID="lblquestion" runat="server"></asp:Label>
            <td class="style1">
                <asp:Label ID="lbla" runat="server"></asp:Label>
                <asp:Label ID="lblb" runat="server"></asp:Label>
            <td class="style1">
                <asp:Label ID="lblc" runat="server"></asp:Label>
                <asp:Label ID="lbld" runat="server"></asp:Label>
            Choose your option:
                <asp:RadioButtonList ID="RadioButtonList1" runat="server" Width="168px">
                    <asp:ListItem Value="opt_A">Option A</asp:ListItem>
                    <asp:ListItem Value="opt_B">Option B</asp:ListItem>
                    <asp:ListItem Value="opt_C">Option C</asp:ListItem>
                    <asp:ListItem Value="opt_D">Option D</asp:ListItem>
            <td class="style1">
                <asp:Button ID="btn_last" runat="server" Text="Last" Width="62px" />
                <asp:Button ID="btn_prev" runat="server" Text="Previous" />
                <asp:Button ID="btn_next" runat="server" Text="Next" Width="56px" />
                <asp:Button ID="btn_first" runat="server" Text="First" Width="83px" />
                Enter the question number you want to view</td>

                <asp:TextBox ID="txt_ques" runat="server"></asp:TextBox>
                <asp:Button ID="btn_ques" runat="server" Text="Submit" />

            <td colspan=2 align=center>
                <asp:Button ID="btn_exam" runat="server" Text="Submit Exam" />
            <br />
            <br />

         <div class="footer">
        <marquee color="red"> Welcome To FAMT's Gneric Examination System</marquee>


Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class Exam
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim cs As String
        Dim con, con1 As SqlConnection
        Dim cmd, cmd1 As SqlCommand
        Dim dr, dr1 As SqlDataReader
        Dim no, i As Integer
        Dim ex, temp, sql As String
        temp = ""
        ex = CType(Session.Item("exam"), String)
        cs = ConfigurationManager.ConnectionStrings("dbconnection").ToString
        con = New SqlConnection(cs)
        cmd = New SqlCommand("Select * from Exams where Exam_id='" + ex + "'", con)
        dr = cmd.ExecuteReader
        no = UInt32.Parse(dr(2).ToString)

        For index = 3 To 22

            If dr(index).ToString <> vbNullString Then

                If index = 22 Or dr(index + 1).ToString = vbNullString Then
                    temp = temp + "'" + dr(index).ToString + "'"
                    temp = temp + "'" + dr(index).ToString + "'" + ","
                End If

            End If
        temp = temp
        con1 = New SqlConnection(cs)
        sql = "Select * from Questions where Qid in(" + temp + ")"
        cmd1 = New SqlCommand(sql, con1)
        'cmd1.Parameters.AddWithValue("@temp", temp)
        dr1 = cmd1.ExecuteReader
        lblquestion.Text = dr1(3).ToString
        lbla.Text = dr1(4).ToString
        lblb.Text = dr1(5).ToString
        lblc.Text = dr1(6).ToString
        lbld.Text = dr1(7).ToString

    End Sub
End Class

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900