My program is supposed to take team names from an XML file and display them in the listbox, and when a team is selected from the listbox, players with a higher batting average on the team are displayed in a datagridview. For some reason nothing is showing up in my listbox, and therefore I cannot select anything and test if my program works.
public partial class Form1 : Form
{
DataSet resultset = new DataSet();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
resultset.ReadXml("Baseball.xml");
var myQuery = resultset.Tables[0].AsEnumerable().Select(row => new
{
teamname = row.Field<string>("Team")
})
.Distinct();
foreach (var rowname in myQuery)
{
listBox1.Items.Add(rowname.teamname.ToString());
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
double TotalhitsAverage, TotalatBatAverage, TeamAverage;
DataTable playerInformation = new DataTable();
DataRow[] tableName = resultset.Tables[0].Select("Team = '" + listBox1.SelectedItem + "'");
playerInformation = tableName.CopyToDataTable();
DataTable clonedcolumns = playerInformation.Clone();
clonedcolumns.Columns[3].DataType = typeof(double);
clonedcolumns.Columns[2].DataType = typeof(double);
foreach (DataRow row in playerInformation.Rows)
{
clonedcolumns.ImportRow(row);
}
TotalhitsAverage = clonedcolumns.AsEnumerable().Average(r => r.Field<double>("hits"));
TotalatBatAverage = clonedcolumns.AsEnumerable().Average(r => r.Field<double>("atBats"));
TeamAverage = TotalhitsAverage / TotalatBatAverage;
DataTable playerAverage = new DataTable();
DataRow rowPlayer = playerAverage.NewRow();
playerAverage.Columns.Add("Player", typeof(String));
playerAverage.Columns.Add("Batting Avg", typeof(double));
for (int i = 0; i < clonedcolumns.Rows.Count; i++)
{
double averageplayer = Convert.ToDouble(clonedcolumns.Rows[i][3]) / Convert.ToDouble(clonedcolumns.Rows[i][2]);
if (TeamAverage <= averageplayer)
{
playerAverage.Rows.Add(clonedcolumns.Rows[i][0].ToString(), Math.Round(averageplayer, 4));
}
}
DataView view = playerAverage.DefaultView;
view.Sort = "Batting Avg DESC";
DataTable sortedDate = view.ToTable();
dgvBaseball.DataSource = sortedDate;
dgvBaseball.AutoSize = true;
}
}
Related
I am trying to make Datagridview paging, I have already performed the paging and it works fine, the problem is when I try to search for records from the database the problem is that Datagridview doesn't change and the data returned from the database is not showing and the pages count keeps increasing on each search.
Please take a look at this video :
https://www.youtube.com/watch?v=Ina0OlZagSo&ab_channel=RabeeQabaha
here is my Custom Datagridview class:
class GV_Paging : Guna.UI2.WinForms.Guna2DataGridView
{
public int PageSize
{
get
{
return _pageSize;
}
set
{
_pageSize = value;
}
}
public int _pageSize = 10;
BindingSource bs = new BindingSource();
BindingList<DataTable> tables = new BindingList<DataTable>();
public void SetPagedDataSource(DataTable dataTable, BindingNavigator bnav)
{
DataTable dt = null;
int counter = 1;
foreach (DataRow dr in dataTable.Rows)
{
if (counter == 1)
{
dt = dataTable.Clone();
tables.Add(dt);
}
dt.Rows.Add(dr.ItemArray);
if (PageSize < ++counter)
{
counter = 1;
}
}
bnav.BindingSource = bs;
bs.DataSource = tables;
bs.PositionChanged += Bs_PositionChanged;
Bs_PositionChanged(bs, EventArgs.Empty);
}
void Bs_PositionChanged(object sender, EventArgs e)
{
this.DataSource = tables[bs.Position];
}
}
and this is how I fill the data to Datagridview:
GV.PageSize = Convert.ToInt32(Math.Floor(Convert.ToDecimal(GV.Height / GV.RowTemplate.Height))) - 1;
DT = DBConn.ExecuteDataTable("select_all_materials", CommandType.StoredProcedure);
GV.SetPagedDataSource(DT, bindingNavigator1);
and here is the code for searching data from the database(work on text box text change):
GV.PageSize = Convert.ToInt32(Math.Floor(Convert.ToDecimal(GV.Height / GV.RowTemplate.Height))) - 1;
DT = DBConn.ExecuteDataTable("search_materials_by_name", CommandType.StoredProcedure, new
SqlParameter[] { new SqlParameter("#name", Material_name_txt.Text.Trim()) });
GV.SetPagedDataSource(DT, bindingNavigator1);
after working on it I was able to fix the problem, here is the working class:
public int PageSize
{
get
{
return _pageSize;
}
set
{
_pageSize = value;
}
}
public int _pageSize = 10;
BindingSource bs;//= new BindingSource();
BindingList<DataTable> tables;// = new BindingList<DataTable>();
public void SetPagedDataSource(DataTable dataTable, BindingNavigator bnav)
{
if (dataTable == null || bnav == null)
{
return;
}
DataTable dt = null;
bs = new BindingSource();
tables = new BindingList<DataTable>();
int counter = 1;
foreach (DataRow dr in dataTable.Rows)
{
if (counter == 1)
{
dt = dataTable.Clone();
tables.Add(dt);
}
dt.Rows.Add(dr.ItemArray);
if (PageSize < ++counter)
{
counter = 1;
}
}
bnav.BindingSource = bs;
bs.DataSource = tables;
bs.PositionChanged += Bs_PositionChanged;
Bs_PositionChanged(bs, EventArgs.Empty);
}
void Bs_PositionChanged(object sender, EventArgs e)
{
try
{
this.DataSource = tables[bs.Position];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
I have a table having 2 columns viz ID and DETAILS.Data in a table is like
id=01 details="pritam=123 sourav=263" like this
i am working on a windows for application ..when the application will run the output comes what i am going to tell.. 1.in my application one combobox is there.when the application will run all the id will be bind in a combobox from the table. 2.when user will choose any id suddenly the details column data will be shown in a datagrid view in a splitted format like this.
NAME KEY
PRITAM 123
SOURAV 263
in this data grid view user can delete ant row by selecting the and click on the below delete button. insert any row by clickng the add new row button at the end ,modify any existing data and finally click on the update button and all the data are going to be stored in that data base like in previous format.. for that i have written the code in c# like this..
namespace windows_csharpp
{
public partial class Form5 : Form
{
SqlConnection cc = new SqlConnection("Integrated Security=true;database=EDIXfer");
SqlDataAdapter da;
DataTable dt;
public Form5()
{
InitializeComponent();
}
private void Form5_Load(object sender, EventArgs e)
{
string sql="select EDIScheduleID from ETAProcessSchedule";
da= new SqlDataAdapter(sql, cc);
dt = new System.Data.DataTable();
da.Fill(dt);
for (int x = 0; x < dt.Rows.Count; x++)
{
comboBox1.Items.Add(dt.Rows[x][0].ToString());
}
}
ArrayList ls = new ArrayList();
int ss = 0;
int ss1 = 0;
int ssp = 1;
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string sql = "select * from ETAProcessSchedule where EDIScheduleID='" + comboBox1.SelectedItem.ToString() + "'";
SqlDataAdapter adp = new SqlDataAdapter(sql, cc);
DataTable dt = new System.Data.DataTable();
adp.Fill(dt);
string stp = dt.Rows[0][21].ToString();
string[] stp1 = stp.Split(' ');
List<Class1> lst = new List<Class1>();
ls.Clear();
for (int x = 0; x < stp1.Length; x++)
{
ls.Add(stp1[x].ToString());
}
for (int x = 0; x < ls.Count; x++)
{
string ssttt = ls[x].ToString();
string[] sssp = ssttt.Split('=');
for (int x1 = 1; x1 < sssp.Length; x1++)
{
ss = 0;
ss1 = ssp;
Class1 cs = new Class1()
{
Value = sssp[ss], Key= sssp[x1].ToString()
};
lst.Add(cs);
}
}
dataGridView1.DataSource = lst;
}
private void Update_Click(object sender, EventArgs e)
{
string value = null;
string keys = null;
string query = null;
string str = null;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
value = dataGridView1.Rows[i].Cells[0].Value.ToString();
keys = dataGridView1.Rows[i].Cells[1].Value.ToString();
string ss = value + '=' + keys;
str += ss + ' ';
}
query = "update ETAProcessSchedule set ProcParameters='"+str+"' where EDIScheduleID='"+comboBox1.SelectedItem.ToString()+"'";
da = new SqlDataAdapter(query, cc);
dt = new DataTable();
da.Fill(dt);
MessageBox.Show("Data Updated In Database Successfully");
}
and one class file is also there ..
class Class1
{
public string Value { get; set; }
public string Key { get; set; }
}
kindly help me in delete the selected row ,add the new row and update the all data in database like in previous format..
I think you already have working approach. If I understand right you need only two functions:
- Load Schedule details in the DataGridView (one key-value pair per row)
- Save edited/added/deleted key-value pairs to the database
Be sure next properties of DataGridView set to true:
this.YourDataGridView.AllowUserToAddRows = true;
this.YourDataGridView.AllowUserToDeleteRows = true;
And of course columns must be editable
In the methods was used const variables which was created in your Form (Form1)
private const string DETAILSDELIMITER = ' ';
private const string NAMEKEYDELIMITER = '=';
Method for loading schedule details in the DataGridView
//Use SqlParameters in the query,
//if not your application vulnerable for sql injection
private void LoadScheduleDetails(string scheduleID)
{
//You working only with one column, do not use '*' in SELECT statement if not nessesary
string query = "SELECT EDIScheduleID, ProcParameters FROM ETAProcessSchedule WHERE EDIScheduleID = #ScheduleID";
DataTable details = new DataTable();
//Get data from database
using (SqlConnection yourConnection = new SqlConnection(_YourConnectionString))
{
using(SqlCommand detailsCommand = new SqlCommand(query, yourConnection))
{
//Adding parameter
SqlParameter id = new SqlParameter { ParameterName = "#ScheduleID", SqlDbType = SqlDbType.NVarChar, Value = scheduleID };
detailsCommand.Parameters.Add(id);
using (SqlDataAdapter yourAdapter = new SqlDataAdapter(detailsCommand ))
{
yourAdapter.Fill(details);
}
}
}
this.YourDataGridView.Rows.Clear();
if (details.Rows.Count > 0)
{
DataRow temp = details.Rows[0];
//get column by name.
string[] pairs = temp.Field<String>("ProcParameters").Split(Form1.DETAILSDELIMITER);
//Adding rows manually without DataSource
foreach(string pair in pairs)
{
this.YourDataGridView.Rows.Add(pair.Split(Form1.NAMEKEYDELIMITER));
}
}
}
Method for saving data
I think better if you create columns already in the designer
Then you can access columns by it's name without hardcoding indexes
private void SaveDetails(string scheduleID)
{
StringBuilder details = new StringBuilder();
foreach(DataGridViewRow dgvr in this.YourDataGridView.Rows)
{
string name = dgvr.Cells[this.dgvColumn_Name.Name].Value.ToString();
string key = dgvr.Cells[this.dgvColumn_Key.Name].Value.ToString();
//Here you can check if values are ok(not empty or something else)
//Create pair
details.Append(Form1.DETAILSDELIMITER);
details.Append(name);
details.Append(Form1.NAMEKEYDELIMITER);
details.Append(key);
}
//remove first space character
if (details.Length > 0)
details.Remove(0, 1);
//Save data to database
string query = "UPDATE ETAProcessSchedule SET ProcParameters=#Details WHERE EDIScheduleID=#ScheduleID";
using (SqlConnection yourConnection = new SqlConnection(_YourConnectionString))
{
using (SqlCommand saveCommand = new SqlCommand(query, yourConnection))
{
//Adding parameters
SqlParameter id = new SqlParameter { ParameterName = "#ScheduleID", SqlDbType = SqlDbType.NVarChar, Value = scheduleID };
SqlParameter procParams = new SqlParameter { ParameterName = "#Details", SqlDbType = SqlDbType.NVarChar, Value = details.ToString() };
saveCommand.Parameters.Add(id);
saveCommand.Parameters.Add(procParams);
saveCommand.ExecuteNonQuery();
MessageBox.Show("Data Updated In Database Successfully");
}
}
}
Then use LoadScheduleDetails in the comboBox1_SelectedIndexChanged eventhandler
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string scheduleID = comboBox1.SelectedItem.ToString();
if(String.IsNullOrEmpty(scheduleID) == false)
{
this.LoadScheduleDetails(scheduleID);
}
}
After data loaded, user can change it, add rows, delete rows
When user pressed "Update" button then use SaveDetails method,
where we collect data from all rows and update database with it
private void Update_Click(object sender, EventArgs e)
{
string scheduleID = comboBox1.SelectedItem.ToString();
if(String.IsNullOrEmpty(scheduleID) == false)
{
this.SaveDetails(scheduleID);
}
}
On your form load bind data:-
EDIT : -
private void Form5_Load(object sender, EventArgs e)
{
comboBox1.DataSource = loadddltable();
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "ID";
}
public DataTable loadddl()
{
OleDbDataReader obj = null;
DataTable dt = new DataTable();
try
{
obj_dbconnection.CommandText = "Select * from TableName";
obj = obj_dbconnection.ExecuteReader();
if (obj != null)
{
if (obj.HasRows)
{
dt.Load(obj);
}
}
}
catch (Exception)
{
}
finally
{
if (obj != null)
{
obj.Close();
obj_dbconnection.Close();
}
}
return dt;
}
/*Code for Execute Reader*/
public OleDbDataReader ExecuteReader()
{
OleDbDataReader dr = null;
try
{
Open();
dr = cmd.ExecuteReader();
}
catch(Exception)
{ }
return dr;
}
/*Code for binding grid data*/
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
dataGridView1.DataSource= getDataForSelectedId(comboBox1.SelectedValue);
}
And then insert,edit,delete buttons as template fields to dataGridView and use dataGridView1_CellClick event to insert edit delete
I have a datagrid view and it's datasource is MS Access(which have a datatype, currency, date/time, and numbers), It shows data in the database but doesn't show other data types, only words or any string, here is my code for adding rows
string[] rowData = new string[columnCount];
while (dr.Read())
{
for (int k = 0; k < columnCount; k++)
{
if (dr.GetFieldType(k).ToString() == "System.int32")
{
rowData[k] = dr.GetInt32(k).ToString();
}
if (dr.GetFieldType(k).ToString() == "System.String")
{
rowData[k] = dr.GetString(k);
}
}
dataGridView1.Rows.Add(rowData);
}
can you help me with this? thanks
Instead of using the code above, I use this code, and it works
private void Form6_Load(object sender, EventArgs e)
{
loadData();
}
private void loadData()
{
str = new OleDbConnectionStringBuilder();
str.Provider = "Microsoft.ace.Oledb.12.0";
str.DataSource = #"\\sisc-erelim\4_Printing\VTDB\DB\VirginiTEADB2.accdb";
con = new OleDbConnection(str.ConnectionString);
dataGridView1.DataSource = fillTable("Select* from Accountstbl");
dataGridView1.Columns["Password"].Visible = false;
dataGridView1.Columns["Picture"].Visible = false;
}
private DataTable fillTable(string sql)
{
DataTable datatable = new DataTable();
using (OleDbDataAdapter da = new OleDbDataAdapter(sql, con))
{
da.Fill(datatable);
}
return datatable;
}
I am populating a ListView with two data sets from SQL. This happens every 15 seconds. How can I keep the scrolled-to position and still refresh the data? I have seen some questions here with related issues but none really address my specific issue. I have tried the TopMost option with limited success.
Any suggestions on how I can keep the scrolled-to position? Here is a bit of code that I use to populate the data for the ListBox.
private void PopulateData()
{
_agent.Stop();
listView1.Items.Clear();
listView1.Groups.Clear();
listView1.BeginUpdate();
string filter;
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
dt1.Columns.Add("Name", typeof(string));
dt1.Columns.Add("Status", typeof(string));
dt1.Columns.Add("Time", typeof(double));
dt1.Columns.Add("Calls", typeof(double));
dt1.Columns.Add("InProgress", typeof(double));
dt1.Columns.Add("Region", typeof(string));
dt2.Columns.Add("Name", typeof(string));
dt2.Columns.Add("CChats", typeof(double));
dt2.Columns.Add("AChats", typeof(double));
foreach (DataRow dr in _agentStates.Rows)
{
DataRow row = dt1.NewRow();
row["Name"] = dr[0].ToString();
row["Status"] = dr[1].ToString();
row["Time"] = Convert.ToDouble(dr[2].ToString());
row["Calls"] = Convert.ToDouble(dr[3].ToString());
row["InProgress"] = Convert.ToDouble(dr[4].ToString());
row["Region"] = dr[5].ToString();
dt1.Rows.Add(row);
}
foreach (DataRow dr in _chatCount.Rows)
{
DataRow row = dt2.NewRow();
row["Name"] = dr[0].ToString();
row["CChats"] = Convert.ToDouble(dr[1].ToString());
row["AChats"] = Convert.ToDouble(dr[2].ToString());
dt2.Rows.Add(row);
}
var result = from table1 in dt1.AsEnumerable()
join table2 in dt2.AsEnumerable()
on (string)table1["Name"] equals (string)table2["Name"]
into joinedDt
from table2 in joinedDt.DefaultIfEmpty()
select new
{
Name = (string)table1["Name"],
Status = (string)table1["Status"],
Time = (double)table1["Time"],
Calls = (double)table1["Calls"],
InProgress = (double)table1["InProgress"],
Region = (string)table1["Region"],
CChats = (table2 != null ? (double)table2["CChats"] : 0),
AChats = (table2 != null ? (double)table2["AChats"] : 0)
};
foreach (var item in result)
{
if (item.Status != "NLO" && item.Status !="Webchat Account")
{
var calls = item.Calls + item.CChats;
var lvi = new ListViewItem(item.Name);
lvi.SubItems.Add(item.Status);
lvi.SubItems.Add(Conv.Time(item.Time));
lvi.SubItems.Add(item.Calls.ToString());
lvi.SubItems.Add(item.CChats.ToString());
lvi.SubItems.Add((item.AChats + item.InProgress).ToString());
lvi.SubItems.Add(calls.ToString());
this.listView1.Items.Add(lvi);
}
}
listView1.EndUpdate();
_agent.Start();
}
Use the listview in VirtualMode mode and implement the RetrieveVirtualItem event.
It will give you a better control over what is visible, and you don't need to clear all items to get it updated.
If VirtualMode is set to true, you just set the VirtualListSize to the number of items you want to display in the list. The RetrieveVirtualItem event will be fired for each item the listview wants to show to the user. So if your data changes, you can call the Refresh method of the listview and your RetrieveVirtualItem handler will return the new item data.
Consider this example:
public partial class Form1 : Form
{
private int i = 0;
public Form1()
{
InitializeComponent();
listView1.View = View.Details;
listView1.Columns.Add("Col", 250);
listView1.VirtualMode = true;
listView1.RetrieveVirtualItem += listView1_RetrieveVirtualItem;
listView1.VirtualListSize = 25;
button1.Click += button1_Click;
}
private void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
e.Item = new ListViewItem((i + e.ItemIndex).ToString());
}
private void button1_Click(object sender, EventArgs e)
{
// simulate data update
i += 10;
//listView1.VirtualListSize += 5; // you can even change the virtual list size while keeping current scroll position
listView1.Refresh();
}
}
I am developing an online exam system project using ASP.NET (C#) & SQL Sever.
This is my code. I have a problem in implementing code for next & previous button. Please suggest me the answer. Thank you.
public partial class Default : Page
{
int count;
string ans;
int[] a=new int[5];
int t;
int ctr;
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
DateTime myDate;
DataTable dt = new DataTable();
DataRow dr;
public void Show()
{
Session["Answered"] = dt;
View v = this.View1;
Label l = default(Label);
l = (Label)v.FindControl("Label1");
l.Text = dt.Rows[ctr]["Serial"] + ".";
l = (Label)v.FindControl("Label2");
l.Text = dt.Rows[ctr]["question"].ToString();
RadioButtonList r = default(RadioButtonList);
r = (RadioButtonList)v.FindControl("RadioButtonList1");
r.Items.Clear();
r.Items.Add(dt.Rows[ctr]["choice1"].ToString());
r.Items.Add(dt.Rows[ctr]["choice2"].ToString());
r.Items.Add(dt.Rows[ctr]["choice3"].ToString());
r.Items.Add(dt.Rows[ctr]["choice4"].ToString());
r.SelectedIndex = Convert.ToInt32(dt.Rows[ctr]["selected"]);
Session["ctr"] = ctr;
}
protected void Timer1_Tick(object sender, System.EventArgs e)
{
DateTime mydate2 = DateTime.Now;
DateTime mydate3 = default(DateTime);
try
{
mydate3 = Convert.ToDateTime((myDate - mydate2).ToString());
this.Label5.Text = "Time Left: " + mydate3.ToShortTimeString();
}
catch (Exception ex)
{
this.Label5.Text = "Error Setting up the Timer. Contact Admin";
}
if (mydate3.ToShortTimeString() == "00:00:00")
{
int marks = 0;
Session["Answered"] = dt;
Response.Redirect("default3.aspx?marks=" + marks);
}
}
protected void Page_Load(object sender, System.EventArgs e)
{
DateTime myDate = new DateTime();
myDate =Convert.ToDateTime(Request.Cookies["start"].Value);
if (!IsPostBack) {
this.MultiView1.ActiveViewIndex = 0;
conn.Open();
cmd.Connection = conn;
Random arbit = new Random();
for (int i = 0; i <= a.GetUpperBound(0); i++) {
t = arbit.Next(1, 10);
if (Array.IndexOf(a, t) == -1) {
a[i] = t;
} else {
goto X;
}
}
for (int i = 0; i <= 4; i++)
{
cmd.CommandText = "select * from test where Serial=" + a[i];
da.SelectCommand = cmd;
da.Fill(ds, "test");
}
conn.Close();
dt = new DataTable("Answered");
dt.Columns.Add("Serial", typeof(int));
dt.Columns.Add("question", typeof(string));
dt.Columns.Add("choice1", typeof(string));
dt.Columns.Add("choice2", typeof(string));
dt.Columns.Add("choice3", typeof(string));
dt.Columns.Add("choice4", typeof(string));
dt.Columns.Add("correct", typeof(string));
dt.Columns.Add("selected", typeof(int));
DataRow r = null;
foreach (DataRow r_loopVariable in ds.Tables["test"].Rows) {
r = r_loopVariable;
dr = dt.NewRow();
dr["Serial"] = dt.Rows.Count + 1;
dr["question"] = r["question"];
dr["choice1"] = r["choice1"];
dr["choice2"] = r["choice2"];
dr["choice3"] = r["choice3"];
dr["choice4"] = r["choice4"];
dr["correct"] = r["correct"];
dr["selected"] = -1;
dt.Rows.Add(dr);
}
Session["Answered"] = dt;
Show();
}
}
protected void btnNext_Click(object sender, EventArgs e)
{
Session["ctr"] = ctr;
Session["Answered"] = dt;
Session["ctr"] = ctr;
ctr += 1;
Show();
if (ctr == 4)
{
this.btnNext.Enabled = false;
}
this.btnPrev.Enabled = true;
}
protected void btnPrev_Click(object sender, EventArgs e)
{
Session["ctr"] = ctr;
Session["Answered"] = dt;
ctr = ctr - 1;
if (ctr == 0)
{
this.btnPrev.Enabled = false;
}
Session["ctr"] = ctr;
this.btnNext.Enabled = true;
Show();
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
RadioButtonList1.SelectedIndexChanged += new EventHandler(RadioButtonList1_SelectedIndexChanged);
Session["Answered"] = dt;
}
protected void btnShowMarks_Click(object sender, EventArgs e)
{
int marks = 0;
Session["Answered"] = dt;
Response.Redirect("default3.aspx?marks=" + marks);
Session["marks"] = dt;
int []b=new int[6];
foreach (int c in b)
{
RadioButtonList1.SelectedIndex.ToString();
}
}
}
I would suggest you to use the Wizard control.
Here are some examples:
http://msdn.microsoft.com/en-us/magazine/cc163894.aspx
http://www.codeproject.com/KB/aspnet/Wizard_Control.aspx
Since you seem to develop a wizard-like form did you consider using the Wizard control.
You can Fetch random data from DB and store it in a dataset. Then there you can get questions in usual manner. Then you can fetch questions using a variable which will store the question number to get previous and next questions. If user clicks on Previous then variable - 1 also +1 if next