I have placed MultiView in UpdatePanel and added Views dynamically, each has GridView control. I'm able to display only the View which is set at first time. I have added static button for "Next" & "Back". An error "ActiveViewIndex is being set to '0'. It must be smaller than the current number of View controls '0'. For dynamically added views, make sure they are added before or in Page_PreInit event.Parameter name: value" occurs, when I click any button including these two.
Code-behind:
protected void MultiView1_Load(object sender, EventArgs e)
{
try
{
if (DropDownList4.SelectedIndex > 0)
{
int i = 1;
SqlCommand cmd = new SqlCommand("select DISTINCT(schedule) from tender where project = '" + DropDownList1.SelectedItem.ToString() + "'", agr);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
string schedule = dr[0].ToString().Trim();
GridView Gridview1 = new GridView();
Gridview1.ID = "Gridview" + i.ToString();
Gridview1.RowDataBound +=new GridViewRowEventHandler(Gridview1_RowDataBound);
Gridview1.EnableViewState = true;
Gridview1.HeaderStyle.BackColor = System.Drawing.Color.Silver;
Gridview1.HeaderStyle.ForeColor = System.Drawing.Color.White;
Gridview1.HeaderStyle.Font.Bold = true;
Gridview1.ForeColor = System.Drawing.Color.Gray;
Gridview1.AlternatingRowStyle.BackColor = System.Drawing.Color.White;
Gridview1.GridLines = GridLines.None;
Gridview1.RowStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#EFF3FB");
Gridview1.HorizontalAlign = HorizontalAlign.Center;
Gridview1.Width = 900;
DataTable dt = new DataTable();
dt.Columns.Add("SN", typeof(string));
dt.Columns.Add("SCHEDULE", typeof(string));
dt.Columns.Add("MATERIAL", typeof(string));
dt.Columns.Add("UNIT", typeof(string));
dt.Columns.Add("PREVIOUS BOQ QTY", typeof(string));
dt.Columns.Add("CURRENT QTY", typeof(string));
int j = 1;
SqlCommand cmd1 = new SqlCommand("select material from tender where project = '" + DropDownList1.SelectedItem.ToString() + "' AND schedule = '" + schedule + "' order by schedulesubsn ", agr);
SqlDataReader dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{
DataRow row = dt.NewRow();
string mat = dr1[0].ToString().Trim();
row["SN"] = j;
row["SCHEDULE"] = schedule;
row["MATERIAL"] = mat;
row["UNIT"] = Calfunc.getunit(mat);
row["PREVIOUS BOQ QTY"] = Calfunc.GetLocationBOQ(DropDownList1.SelectedItem.ToString(), DropDownList2.SelectedItem.ToString(), DropDownList3.SelectedItem.ToString(), DropDownList4.SelectedItem.ToString(), schedule, mat);
dt.Rows.Add(row);
j++;
}
dr1.Dispose();
View view = new View();
view.ID = schedule;
view.Controls.Add(Gridview1);
MultiView1.Views.Add(view);
Gridview1.DataSource = dt;
Gridview1.DataBind();
i++;
}
dr.Dispose();
MultiView1.ActiveViewIndex = i-3;
}
}
catch (Exception ex)
{
}
}
protected void Button3_Click(object sender, EventArgs e)
{
if (MultiView1.ActiveViewIndex > 0)
{
MultiView1.ActiveViewIndex = MultiView1.ActiveViewIndex - 1;
}
}
protected void Button4_Click(object sender, EventArgs e)
{
if (MultiView1.Views.Count-1 > MultiView1.ActiveViewIndex)
{
TextBox2.Text = (MultiView1.ActiveViewIndex + 1).ToString();
}
}
protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox TextBox101 = new TextBox();
TextBox101.ID = "TextBox_C_QTY";
TextBox101.Width = 70;
TextBox101.Text = (e.Row.DataItem as DataRowView).Row["CURRENT QTY"].ToString();
e.Row.Cells[5].Controls.Add(TextBox101);
}
}
aspx:
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<div style="overflow-x:auto;">
<asp:MultiView ID="MultiView1" runat="server" onload="MultiView1_Load">
</asp:MultiView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
I've searched for the solution but didn't find any satisfactory or workable (for me).
Related
In my project, I can add n number of textbox in gridview dynamically. My problem is, I want to fire textboxchanged event, if user change the text of any textbox in any row of gridview.
HTML CODE:
<asp:GridView ID="GridView1" runat="server"
Width="907px" style="text-align: center" CellPadding="4" ForeColor="#333333"
GridLines="None" onrowdatabound="GridView1_RowDataBound">
</asp:GridView>
ADDING COLUMNS IN GRIDVIEW:
foreach (string a in crcl)
{
SqlCommand cmd1 = new SqlCommand("select qty from purchaseinstruction where project ='" + DropDownList1.SelectedItem.ToString() + "' AND circle = '" + a + "' AND item = 'BIFURCATION' AND material = '" + mat + "'", agr);
SqlDataReader dr1 = cmd1.ExecuteReader();
if (dr1.Read())
{
string val = dr1[0].ToString();
if (val.Length > 0)
{
row[a] = val;
}
else
{
row[a] = 0;
}
}
else
{
row[a] = 0;
}
dr1.Dispose();
}
dt.Rows.Add(row);
GridView1.DataSource = dt;
GridView1.DataBind();
ADDING TEXTBOX ON ROWBOUND:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i = 3;
if (e.Row.RowType == DataControlRowType.DataRow)
{
crcl = (List<string>)ViewState["bdi2"];
foreach(string a in crcl)
{
TextBox TextBox101 = new TextBox();
TextBox101.ID=a;
TextBox101.Width = 60;
TextBox101.Text = (e.Row.DataItem as DataRowView).Row[a].ToString();
TextBox101.AutoPostBack = true;
e.Row.Cells[i].Controls.Add(TextBox101);
i++;
}
}
}
Here I have three problems
1. After postback textboxs get dispose
2. How to retain the value of textboxes for textboxchange?
3. How to know which textbox fire textboxchange
I have a gridview and output generated is
But I want to remove the Column_Name column and want this type of output
Never change SQL query because in this way the query works according to my logic. And I also want to remove   in every textbox and how can I get all the gridview data by using loop and save in SQL Server database?
ASPX:
<asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server">
<form id="form" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true"
onrowdatabound="GridView1_RowDataBound">
</asp:GridView>
<asp:Button ID="Button1" runat="server" OnClick="load" Text="gridview" />
<asp:Button ID="Button2" runat="server" OnClick="show" Text="Button" />
<asp:Button ID="Button3" runat="server" OnClick="save" Text="Save" />
</form>
</asp:Content>
Codebehind:
SqlConnection cnn = new SqlConnection("Data Source=LIFE_WELL;Initial Catalog=db_compiler;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
string query = "USE db_compiler SELECT Column_Name FROM tbl_field WHERE Table_Name='deptt'";
SqlCommand cmd = new SqlCommand(query, cnn);
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable table = new DataTable();
adp.Fill(dt);
Session["num"] = dt.Rows.Count;
for (int i = 0; i < dt.Rows.Count; i++)
{
DataColumn dc = new DataColumn(dt.Rows[i]["Column_Name"].ToString());
dt.Columns.Add(dc);
}
DataRow r = table.NewRow();
GridView1.DataSource = table;
GridView1.DataBind();
cnn.Close();
cnn.Open();
cmd.ExecuteNonQuery();
cnn.Close();
Session["table"] = dt;
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
TextBox txt = new TextBox();
txt.Text = e.Row.Cells[i].Text;
e.Row.Cells[i].Text = "";
e.Row.Cells[i].Controls.Add(txt);
}
}
}
Change Your Codebehind code:
protected void Page_Load(object sender, EventArgs e)
{
If(!IsPostBack)
{
string query = "USE db_compiler SELECT Column_Name FROM tbl_field WHERE Table_Name='deptt'";
con.Open();
SqlCommand cmd = new SqlCommand(query, con);
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable table = new DataTable();
adp.Fill(dt);
Session["num"] = dt.Rows.Count;
for (int i = 0; i < dt.Rows.Count; i++)
{
DataColumn dc = new DataColumn(dt.Rows[i]["Name"].ToString());
table.Columns.Add(dc); // Make this Column in 2nd DataTable and bind that to Gridview
}
DataRow r = table.NewRow();
Session["table"] = dt;
table.Rows.Add(r); // Add as many row you want to add with for loop
Gridview1.DataSource = table;
Gridview1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
TextBox txt = new TextBox();
e.Row.Cells[i].Controls.Add(txt);
}
}
}
You can try with this modified RowDataBound event handler:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 1; i < e.Row.Cells.Count; i++) // Does not process the first cell
{
TextBox txt = new TextBox();
TableCell cell = e.Row.Cells[i];
txt.Text = cell.Text.Replace(" ", ""); // Removes
cell.Text = "";
cell.Controls.Add(txt);
}
}
e.Row.Cells.RemoveAt(0); // Removes the first cell in the row
}
I have two dynamically populated radio button lists. The first one gets populated on a button click, the other one on the change event of the first radio button list. The problem is only with the second list. The issue is that I am not able to retrieve the changed value of the second radio button list in the InsertButton_Click method(marked by **). It always returns the default index value i.e 0. I don't have anything in page_load event. I read quite a few similar questions but none seem to help. Please guide. Below is the asp and c# code for the same:
ASP:
<asp:Button id="SaveButton"
Text="Save"
runat="server" onclick="SaveButton_Click">
</asp:Button>
<asp:Button id="VisualiseButton"
Text="Visualise"
runat="server" onclick="VisualiseButton_Click">
</asp:Button>
<!--<hr />-->
<asp:RadioButtonList id="RadioButtonList2" runat="server" Visible="false"
onselectedindexchanged="RadioButtonList2_SelectedIndexChanged" ></asp:RadioButtonList>
<asp:RadioButtonList id="RadioButtonList1" runat="server" Visible="false" ></asp:RadioButtonList>
<asp:Button id="SaveToDBButton"
Text="Insert"
runat="server" Visible="false" onclick="InsertButton_Click">
C#:
protected void SaveButton_Click(object sender, EventArgs e)
{
String selQuery = "SELECT id, name FROM categories";
try
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(selQuery, con);
DataTable dt = new DataTable();
da.Fill(dt);
RadioButtonList2.DataSource = dt;
RadioButtonList2.DataTextField = "name";
RadioButtonList2.DataValueField = "id";
RadioButtonList2.DataBind();
RadioButtonList2.RepeatColumns = 3;
RadioButtonList2.AutoPostBack = true;
RadioButtonList2.Visible = true;
}
catch (SqlException ex)
{
}
finally
{
if (con != null)
{
con.Close();
}
}
}
protected void RadioButtonList2_SelectedIndexChanged(object sender, EventArgs e)
{
String catId = RadioButtonList2.SelectedValue;
SqlCommand cmdselect = new SqlCommand("SELECT DISTINCT categoryId, linkTablesCategories.tableName, tableDescription FROM linkTablesCategories, tableDescriptions where linkTablesCategories.tableName = tableDescriptions.tableName and categoryId ='" + catId + "'");
RadioButtonList1.Items.Clear();
try
{
con.Open();
cmdselect.Connection = con;
SqlDataReader dar = cmdselect.ExecuteReader();
if (dar.HasRows)
{
while (dar.Read())
{
ListItem li = new ListItem(dar["tableName"].ToString(), dar["categoryId"].ToString());
li.Attributes.Add("title", dar["tableDescription"].ToString());
RadioButtonList1.Items.Add(li);
}
}
RadioButtonList1.Visible = true;
SaveToDBButton.Visible = true;
}
catch (SqlException ex)
{
//lblMessage.Text = ex.Message;
}
finally
{
cmdselect.Dispose();
if (con != null)
{
con.Close();
}
}
}
protected void InsertButton_Click(object sender, EventArgs e)
{
String tableId="";
**tableId = RadioButtonList1.SelectedItem.Text;**
String path = Server.MapPath("~/");
string filepath = path + Session["filepath"].ToString();
StreamReader sr = new StreamReader(filepath);
string line = sr.ReadLine();
string[] value = line.Split(',');
DataTable dt = new DataTable();
DataRow row;
foreach (string dc in value)
{
dt.Columns.Add(new DataColumn(dc));
}
while (!sr.EndOfStream)
{
value = sr.ReadLine().Split(',');
if (value.Length == dt.Columns.Count)
{
row = dt.NewRow();
row.ItemArray = value;
dt.Rows.Add(row);
}
}
SqlBulkCopy bc = new SqlBulkCopy(con.ConnectionString, SqlBulkCopyOptions.TableLock);
bc.DestinationTableName = tableId;
bc.BatchSize = dt.Rows.Count;
con.Open();
bc.WriteToServer(dt);
bc.Close();
con.Close();
}
it was with the line:
ListItem li = new ListItem(dar["tableName"].ToString(), dar["categoryId"].ToString());
The categoryId was a constant value and thus the issue, again my bad.
Thanks
I am using window.open to open 2 different pages in pop-up windows,but for some reason both the triggers opens the same page in the pop-up window,heres how I am trying to do this:
first:
Response.Write("<script type='text/javascript'>window.open('TransEditEntry.aspx','mywindow','width=850px,height=300px,left=0,top=10,screenX=100,screenY=10')</script>");
second:
Response.Write(#"<script type='text/javascript'>window.open('TransNewEntry.aspx','','width=850px,height=300px,left=0,top=10,screenX=100,screenY=10')</script>");
this opens 'TransEditEntry.aspx' page instead of 'TransNewEntry.aspx'`
here the rest of the code:
The entire function which is called on add button click:
protected void addNew(object sender, EventArgs e)
{
//HiddenField sr = (HiddenField)GridView1.SelectedRow.Cells[6].FindControl("srno");
//Session["TransSrNo"] = sr.Value;
Response.Write(#"<script type='text/javascript'>window.open('TransNewEntry.aspx','','width=850px,height=300px,left=0,top=10,screenX=100,screenY=10')</script>");
//Session["transAdd"] = "1";
}
The add button which calls the function:
<asp:Button ID="AddBtn" runat="server" OnClick="addNew" Text="Add"/>
The page TransNewEntry.aspx.cs
public partial class TransEditEntry : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(GetConnectionString.Get());
string subCode;
DataTable dt;
SqlDataAdapter sda;
SqlCommandBuilder build;
DataRow dr;
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
Response.Write((Session["TransSrNo"]).ToString());
int SRno = Convert.ToInt32((Session["TransSrNo"]).ToString());
con.Open();
SqlCommand cmd3 = new SqlCommand("select sub_code from tran_dtls where sr_no='" + SRno + "'", con);
subCode = (string)cmd3.ExecuteScalar();
con.Close();
if (!IsPostBack)
{
sda = new SqlDataAdapter("select * from tran_dtls where sr_no=" + SRno + "", con);
build = new SqlCommandBuilder(sda);
dt = new DataTable();
sda.Fill(dt);
foreach (DataRow row in dt.Rows)
{
srNoTxt.Text = "";
amttxt.Text = "";
partTxt.Text = "";
checkNoTxt.Text = "";
checkDtTxt.Text = "";
refNoTxt.Text = "";
refDtTxt.Text = "";
jobNoTxt.Text = "";
}
}
}
protected void GlChange(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd4 = new SqlCommand("select ac_type from ac_mstr where AC_desc='" + GlDrp.SelectedValue + "'", con);
string acType = (string)cmd4.ExecuteScalar();
SqlCommand cmd5 = new SqlCommand("select gl_code from ac_mstr where AC_desc='" + GlDrp.SelectedValue + "'", con);
string gl_code = (string)cmd5.ExecuteScalar();
if (acType == "S")
{
SqlDataSource3.SelectCommand = ("select ac_desc from ac_mstr where gl_code='" + gl_code + "'");
subDrp.DataBind();
subDrp.Enabled = true;
//Response.Write("<script type='javacript/text'>alert('1')</script>");
}
else
{
subDrp.Enabled = false;
//Response.Write("<script type='javacript/text'>alert('2')</script>");
}
con.Close();
}
protected void saveRow(object sender, EventArgs e)
{
int SRno = Convert.ToInt32((Session["TransSrNo"]).ToString());
sda = new SqlDataAdapter("select * from tran_dtls where tc='" + Session["TC"] + "' and doc_no='" + Session["docNo"] + "' ", con);
build = new SqlCommandBuilder(sda);
//dt = new DataTable();
// DataSet ds = new DataSet();
sda.Fill(ds);
dt = (DataTable)ViewState["myViewState"];
if (Session["gridRow"] == null)
{
dt = ds.Tables[0];
dr = dt.NewRow();
dr["GL_code"] = GlDrp.SelectedValue;
dr["sub_code"] = subDrp.SelectedValue;
dr["particulars"] = partTxt.Text;
dr["chq_no"] = checkNoTxt.Text;
dr["chq_dt"] = checkDtTxt.Text;
dr["ref_no"] = refNoTxt.Text;
dr["ref_dt"] = refDtTxt.Text;
dr["dbcr"] = dbcrDrp.SelectedValue.ToString().Substring(0, 1);
dr["amt"] = amttxt.Text;
dr["job_no"] = jobNoTxt.Text;
dr["EMP"] = empDrop.SelectedValue;
dt.Rows.Add(dr);
dt.AcceptChanges();
ViewState["myViewState"] = dt;
//Session["gridRow"] = dt;
Session["gridRow"] = dt;
Session["saveToggle"] = "1";
closeFunction();
Response.Write("<script type='text/javascript'>this.close()</script>");
}
else
{
dt = (DataTable)Session["gridRow"];
dr = dt.NewRow();
dr["GL_code"] = GlDrp.SelectedValue;
dr["sub_code"] = subDrp.SelectedValue;
dr["particulars"] = partTxt.Text;
dr["chq_no"] = checkNoTxt.Text;
dr["chq_dt"] = checkDtTxt.Text;
dr["ref_no"] = refNoTxt.Text;
dr["ref_dt"] = refDtTxt.Text;
dr["dbcr"] = dbcrDrp.SelectedValue.ToString().Substring(0, 1);
dr["amt"] = amttxt.Text;
dr["job_no"] = jobNoTxt.Text;
dr["EMP"] = empDrop.SelectedValue;
dt.Rows.Add(dr);
dt.AcceptChanges();
ViewState["myViewState"] = dt;
//Session["gridRow"] = dt;
Session["gridRow"] = dt;
Session["saveToggle"] = "1";
//Response.Write("<script type='text/javascript'>window.opener.location.reload(true);</script>");
closeFunction();
Response.Write("<script type='text/javascript'>this.close()</script>");
}
}
private void closeFunction()
{
StringBuilder sb = new StringBuilder();
sb.Append("window.opener.RefreshPage();");
sb.Append("window.close();");
ClientScript.RegisterClientScriptBlock(this.GetType(), "CloseWindowScript", sb.ToString(), true);
}
}
Check your condition where you are doing : Response.Write. Both the conditions must be pointing out for first>
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