如何添加两个图像iin gridview条件? [英] How to add two images iin gridview with condition?
问题描述
hi..i有一个问题
如何在asp.net的gridviw中根据条件设置两个图像
i想要点击结果按钮然后正确回答并显示用户回答状态..如果用户回答并且回答正确则显示第一张图像否则第二张图片将显示b显示
结果页面编码:
BL.querystudent objquery = new BL.querystudent(ConfigurationManager。 ConnectionStrings [reetu]。ToString());
static DataTable dt = new DataTable();
static DataTable dtNew = new DataTable();
静态字符串pname;
静态双重结果,标记;
static int marks1,尝试,取消尝试,正确,不正确;
static int eid,stid,pid,sid;
string a,b;
protected void Page_Load(object sender,EventArgs e)< br $>
{
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。行[0] [StudentID]);
string started = Session [start]。ToString();
dt = objquery.getresult(eid,stid ); $
foreach(数据流在dt.Rows中)
{
a = dr [UserAnswer ] .ToString();
b = dr [CorrectAnswer]。ToString();
if((a!=)&& (a == b))
{
尝试+ = 1;
正确+ = 1;
标记+ = 1;
}
否则if((a!=)&&(a!= b))
{
尝试+ = 1;
不正确+ = 1;
标记 - = 0.25;
}
否则if(a ==)
{
unattempt + = 1;
}
}
int n = Convert.ToInt32(no);
结果= 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;
错误= 0;
}
}
templatefield编码:
< asp:TemplateField HeaderText = 状态 >
< ItemTemplate >
< asp:Image ID = Image1 runat = 服务器 ImageUrl =' <% #Eval( Status)== true? 〜/ pics / login-btn.png: 〜/ pics / check.jpg %> ' < span class =code-attribute> / >
< / ItemTemplate >
< / asp:TemplateField >
gridview编码:
BL.querystudent objquery = new BL.querystudent(ConfigurationManager.ConnectionStrings [reetu]。ToString() );
静态DataTable dt = new DataTable();
静态DataTable dtNew = new DataTable();
stati c int stid;
静态字符串stname,tknid;
静态bool状态;
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);
}
}
你可以在GridView RowDataBound事件上检查你的条件
protected void GridView1_RowDataBound( object sender,GridViewRowEventArgs e)
{
标签lblID =(标签)e.Row.FindControl( Your_lblIDName跨度>); // 在GridView中查找控件
图片img =(图片)e。 Row.FindControl( Your_imgName); // 在GridView中查找控件
if (lblID!= null )
{
if (lblID.Text == 2 || lblID。文字== 3)
img.ImageUrl = 在此设置你的图片网址。;
else
img.Visible = false ;
}
}
你可以试试这个链接的网格视图提示和技巧,这里他们解释一下如何根据条件改变网格视图的颜色,你可以使用图像技巧
http://www.dotnetcurry .com / ShowArticle.aspx?ID = 172 [ ^ ]
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);
}
}
u can check ur condition on GridView RowDataBound Event
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { Label lblID = (Label)e.Row.FindControl("Your_lblIDName"); //find control inside GridView Image img = (Image)e.Row.FindControl("Your_imgName"); //find control inside GridView if (lblID != null) { if (lblID.Text == "2" || lblID.Text == "3") img.ImageUrl = "Set ur image url here."; else img.Visible = false; } }
and you can try this link for the grid view tips and tricks, here they explain about how to change the color of the grid view depends on condition, you can use the trick for images
http://www.dotnetcurry.com/ShowArticle.aspx?ID=172[^]
这篇关于如何添加两个图像iin gridview条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!