hi..i have one question
how to set two images according to condtion in gridviw in asp.net
i want when i click on the result button then correct answer and user answer status will be displayed..if user answe and correct answer is true then first image displayed otherwise second image will b displayed
result page coding:
BL.querystudent objquery = new BL.querystudent(ConfigurationManager.ConnectionStrings["reetu"].ToString());
static DataTable dt = new DataTable();
static DataTable dtNew = new DataTable();
static string pname;
static double result,marks;
static int marks1, attempt,unattempt,correct,incorrect;
static int eid, stid,pid,sid;
string a, b;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Label1.Text = Session["Email"].ToString();
string no = Session["no"].ToString();
string name = Session["examname"].ToString();
// pname = Session["programname"].ToString();
dt = objquery.getexamresult(name);
int eid = Convert.ToInt32(dt.Rows[0]["ExamID"]);
string stname = Label1.Text;
dt = objquery.getsid(stname);
int stid = Convert.ToInt32(dt.Rows[0]["StudentID"]);
string started = Session["start"].ToString();
dt = objquery.getresult(eid,stid);
foreach (DataRow dr in dt.Rows)
{
a = dr["UserAnswer"].ToString();
b = dr["CorrectAnswer"].ToString();
if ((a != "") && (a == b))
{
attempt += 1;
correct += 1;
marks += 1;
}
else if ((a != "") && (a != b))
{
attempt += 1;
incorrect += 1;
marks -= 0.25;
}
else if (a == "")
{
unattempt += 1;
}
}
int n = Convert.ToInt32(no);
result = Convert.ToDouble((marks * 100) / n);
TextBox6.Text = no.ToString();
TextBox7.Text = attempt.ToString();
TextBox8.Text = unattempt.ToString();
TextBox1.Text = correct.ToString();
TextBox2.Text = incorrect.ToString();
TextBox9.Text = result.ToString();
attempt = 0;
unattempt = 0;
marks = 0;
marks1 = 0;
correct = 0;
incorrect = 0;
}
}
templatefield coding:
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Status")=="true" ? "~/pics/login-btn.png" : "~/pics/check.jpg"%>' />
</ItemTemplate>
</asp:TemplateField>
gridview coding:
BL.querystudent objquery = new BL.querystudent(ConfigurationManager.ConnectionStrings["reetu"].ToString());
static DataTable dt = new DataTable();
static DataTable dtNew = new DataTable();
static int stid;
static string stname,tknid;
static bool status;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Label1.Text = Session["Email"].ToString();
stname = Label1.Text;
tknid = Session["token"].ToString();
dtNew = objquery.getsid(stname);
stid = Convert.ToInt32(dtNew.Rows[0]["StudentID"]);
bindtogrid();
}
}
public void bindtogrid()
{
dt = objquery.getsturesult(tknid, stid);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (dt.Rows.Count > 0)
{
bindtogrid();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
dt=objquery.getstatus(tknid,stid);
}
}