Hello,
i'm new to ASP.net & 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...
___________________________________________________________________
Exam.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Exam.aspx.vb" Inherits="Exam" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link href="Site.css" rel ="Stylesheet" type="text/css" />
<style type="text/css">
#form1
{
height: 283px;
width: 802px;
}
.style1
{
width: 303px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="page">
<div class="header">
<div class="title">
<h1>
FAMT's Generic Online Examination System
</h1>
</div>
<div class="clear hideSkiplink">
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="~/Shome.aspx" Text="Student Home"/>
</Items>
</asp:Menu>
</div>
</div>
<div class="main">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<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>
</tr>
<tr>
<td class="style1">
<asp:Label ID="lbla" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblb" runat="server"></asp:Label>
</tr>
<tr>
<td class="style1">
<asp:Label ID="lblc" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lbld" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
Choose your option:
</td>
<td>
<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>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="style1">
<asp:Button ID="btn_last" runat="server" Text="Last" Width="62px" />
<asp:Button ID="btn_prev" runat="server" Text="Previous" />
</td>
<td>
<asp:Button ID="btn_next" runat="server" Text="Next" Width="56px" />
<asp:Button ID="btn_first" runat="server" Text="First" Width="83px" />
</td>
</tr>
<tr>
<td>
Enter the question number you want to view</td>
<td>
<asp:TextBox ID="txt_ques" runat="server"></asp:TextBox>
<asp:Button ID="btn_ques" runat="server" Text="Submit" />
</td>
</tr>
<tr>
<td colspan=2 align=center>
<asp:Button ID="btn_exam" runat="server" Text="Submit Exam" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<br />
</div>
<div class="footer">
<marquee color="red"> Welcome To FAMT's Gneric Examination System</marquee>
</div>
</div>
</form>
</body>
</html>
____________________________________________________________________________
Exam.aspx.vb
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)
MsgBox(ex)
cs = ConfigurationManager.ConnectionStrings("dbconnection").ToString
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("Select * from Exams where Exam_id='" + ex + "'", con)
dr = cmd.ExecuteReader
dr.Read()
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 + "'"
Else
temp = temp + "'" + dr(index).ToString + "'" + ","
End If
End If
Next
temp = temp
MsgBox(temp)
dr.Close()
con.Close()
con1 = New SqlConnection(cs)
con1.Open()
sql = "Select * from Questions where Qid in(" + temp + ")"
MsgBox(sql)
cmd1 = New SqlCommand(sql, con1)
'cmd1.Parameters.AddWithValue("@temp", temp)
dr1 = cmd1.ExecuteReader
dr1.Read()
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