Sanjay Patel

Sanjay Patel

  • NA
  • 10
  • 2.6k

change paging color of Repeater on condition

Sep 5 2017 2:50 AM
 
 

I am building a Examination Test Page

Page contening 50 question list show on repeater page size=1

I am using paging

There Are Buttons for save answer of the question

"1-Mark For Review & Next 2-Save & Next"

When i click on save and nest the i want to change the color of pageing of particular question same as for Mark For Review & Next chage different color of pageing

My aspx page in bellow...

 
<asp:Timer ID="timer1" runat="server" Interval="1000" OnTick="timer1_Tick1"></asp:Timer>
<asp:UpdatePanel ID="UpdPanel" runat="server" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1"
EventName="tick" />
</Triggers>
<ContentTemplate>
<div class="courses_box1">
<div id="wrapper" class="container">
<div class="col-md-9 about_left"><%--<asp:Label ID="Label9" runat="server" Font-Bold="true"/> --%>
<h4><asp:Label ID="lbltestName" runat="server" Text="IBPS PO PRELIMARY-" Font-Bold="true"/> <asp:Label ID="lblsubjectText" runat="server" ForeColor="#1fbad6" Font-Bold="true"></asp:Label></h4>
<h4>
<%-- <asp:LinkButton ID="LinkButton1" runat="server" CssClass="link4">LinkButton</asp:LinkButton>--%>
<asp:Button ID="btnEnglish" runat="server" Text="English Language" class="btn btn-default" OnClick="btnEnglish_Click"/>
<asp:Button ID="btnQuantative" runat="server" Text="Quantitative Aptitude" class="btn btn-default" OnClick="btnQuantative_Click" />
<asp:Button ID="btnResoning" runat="server" Text="Reasoning Ability" class="btn btn-default" OnClick="btnResoning_Click" />
</h4>
<asp:Panel ID="pQuestion" runat="server">
<h3><asp:label id="lblQuesNo" runat="server" Font-Bold="True" style="font-size:small;font-family:Arial;"></asp:label></h3>
<div id="scrollDiv" class="verticalscroll">
<table style="width:100%">
<tr>
<td><asp:Repeater ID="rQues" runat="server" OnItemDataBound="rQues_ItemDataBound">
<HeaderTemplate> </HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblAtempted" runat="server" Font-Bold="true"></asp:Label>
<p>
<asp:Label ID="lblDirection" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.Direction")%>'></asp:Label>
</p>
<p> <asp:Label ID="textQuest" runat="server" Text="Question:" Font-Bold="true"></asp:Label><br />
<asp:Label ID="lblQuestion" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.Question")%>'></asp:Label>
</p><br />
<ol type="A">
<li class="list-group-item"> <asp:Label ID="lblOption1" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.Option1")%>'></asp:Label></li>
<li class="list-group-item"> <asp:Label ID="lblOption2" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.Option2")%>'></asp:Label></li>
<li class="list-group-item"> <asp:Label ID="lblOption3" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.Option3")%>'></asp:Label></li>
<li class="list-group-item"> <asp:Label ID="lblOption4" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.Option4")%>'></asp:Label></li>
<li class="list-group-item"> <asp:Label ID="lblOption5" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.Option5")%>'></asp:Label></li>
</ol>
<asp:Label ID="lblCorrectAns" runat="server" Visible="false" Text='<%#DataBinder.Eval(Container, "DataItem.CorrectAns")%>'></asp:Label>
<asp:Label ID="lblQuestionNo" runat="server" Visible="false" Text='<%#DataBinder.Eval(Container, "DataItem.QuestionNo")%>'></asp:Label>
</ItemTemplate>
</asp:Repeater></td>
</tr>
</table></div>
<table>
<tr><td> <asp:Label id="lblSelect" runat="server" Font-Bold="True" style="font-size:small;font-family:Arial;" Text="Select Answer"> </asp:Label></td>
<td><asp:RadioButtonList ID="rblOption" runat="server" RepeatDirection="Horizontal" Text CssClass="rbWidth" >
<asp:ListItem>(A)</asp:ListItem>
<asp:ListItem>(B)</asp:ListItem>
<asp:ListItem>(C)</asp:ListItem>
<asp:ListItem>(D)</asp:ListItem>
<asp:ListItem>(E)</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr></table>
<asp:Button ID="btnClear" runat="server" class="btn btn-primary" Text="Clear Response" OnClick="btnClear_Click" Visible="false" />
<asp:Button ID="btnReview" runat="server" class="btn btn-info" Text="Mark For Review & Next" OnClick="btnReview_Click" Visible="false" OnClientClick="return validate()"/>
<asp:Button ID="btnRevOnly" runat="server" class="btn btn-info" Text="Mark For Review & Next" Visible="false" OnClick="btnRevOnly_Click" OnClientClick="return validate()"/>
<%-- <asp:Button id="btnPrevious" runat="server" class="btn btn-info" text="Previous" onclick="btnPrevious_Click" Visible="false" ></asp:Button>--%>
<asp:Button id="btnNext" runat="server" class="btn btn-info" text="Save & Next" onclick="btnNext_Click" Visible="false" OnClientClick=" return validate()"></asp:Button>
<asp:Button ID="btnSave" runat="server" class="btn btn-info" Text="Save & Next" Visible="false" OnClick="btnSave_Click" OnClientClick="return validate()"/>
<asp:Label ID="lblCorrectAns1" runat="server" Visible="false"/>
<asp:Label ID="lbQNo" runat="server" Visible="false"/>
<asp:Button ID="btnSubmit" runat="server" class="btn btn-success" Text="Submit Test" OnClick="btnSubmit_Click"/>
<asp:Button ID="btnStop" runat="server" class="btn btn-success" Text="Stop Test" OnClick="btnStop_Click"/>
</asp:Panel>
</div>
<div class="col-md-3">
<p>
<asp:Label ID="lblTimeLeft" runat="server" Text="Time Left [min:sec]:" Font-Bold="true" ForeColor="Red"></asp:Label>
<asp:Label ID="textTimeLeft" runat="server" Font-Bold="true"/>
</p>
<br />
<asp:Repeater ID="rptPages" Runat="server" onitemcommand="rptPages_ItemCommand" OnItemDataBound="rptPages_ItemDataBound">
<HeaderTemplate>
<table>
<tr class="text">
<td><b></b>&nbsp;</td>
<td>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="btnPage" CommandName="Page" CommandArgument="<%# Container.DataItem %>" Runat="server" CssClass="btncss"><%# Container.DataItem %> </asp:LinkButton>&nbsp;
</ItemTemplate>
<FooterTemplate>
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="" CssClass="lblAnscss"></asp:Label>&nbsp; <asp:Label ID="Label2" runat="server" Text="Answerd" Font-Bold="true"></asp:Label>
<asp:Label ID="Label3" runat="server" Text="" CssClass="lblmerkcss"></asp:Label>&nbsp; <asp:Label ID="Label4" runat="server" Text="Mark for Review" Font-Bold="true"></asp:Label><br /><br />
<asp:Label ID="Label5" runat="server" Text="" CssClass="lblcurrentcss"></asp:Label>&nbsp; <asp:Label ID="Label6" runat="server" Text="Current" Font-Bold="true"></asp:Label>
<asp:Label ID="Label7" runat="server" Text="" CssClass="lblunseencss"></asp:Label>&nbsp; <asp:Label ID="Label8" runat="server" Text="Unseen" Font-Bold="true"></asp:Label>
</div>
<div class="clearfix"> </div></div></div>
<asp:UpdateProgress runat="server" id="updateProgress1" AssociatedUpdatePanelID="UpdPanel" >
<ProgressTemplate>
<div id="Background"></div>
<div id="Progress">
<img src="images/Prog.gif" style="vertical-align:middle"/>
In Process Please Wait...
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Timer runat="server" Interval="300000" ID="TimerControl2" OnTick="tickerTimer2_Tick" />
<asp:UpdatePanel runat="server" ID="UpdatePanel2" UpdateMode="Always" RenderMode="Inline" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TimerControl2" EventName="Tick" />
</Triggers>
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
 
 
 
 
 
 
 
 
 
code behind
private void Paging()
{
try
{
btnNext.Visible = true;
btnReview.Visible = true;
btnClear.Visible = true;
// btnPrevious.Visible = true;
qHandler qsvc = new qHandler();
PagedDataSource pgitems = new PagedDataSource();
// DataView dv = new DataView(dt);
// subId = "IBPSPOPRIEL";
pgitems.DataSource = qsvc.GetSectQuestions(testType, testid, subId, setNo);
pgitems.AllowPaging = true;
pgitems.PageSize = 1;
pgitems.CurrentPageIndex = PageNumber;
lblQuesNo.Text = "Question: " + (PageNumber + 1).ToString() + " of " + pgitems.PageCount.ToString();
//btnPrevious.Enabled = !Pds1.IsFirstPage;
btnReview.Enabled = !pgitems.IsLastPage;
btnNext.Enabled = !pgitems.IsLastPage;
if (btnNext.Enabled == false)
{
btnSave.Visible = true;
btnRevOnly.Visible = true;
btnNext.Visible = false;
btnReview.Visible = false;
}
if (btnNext.Enabled == true)
{
btnSave.Visible = false;
btnRevOnly.Visible = false;
}
if (pgitems.PageCount > 1)
{
rptPages.Visible = true;
ArrayList pages = new ArrayList();
for (int i = 0; i < pgitems.PageCount; i++)
pages.Add((i + 1).ToString());
// rptPages.DataSource = null;
rptPages.DataSource = pages;
rptPages.DataBind();
}
else
rptPages.Visible = false;
// rQues.DataSource = null;
rQues.DataSource = pgitems;
rQues.DataBind();
}
catch (Exception)
{
//throw;
}
}
public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
return Convert.ToInt32(ViewState["PageNumber"]);
else
return 0;
}
set
{
ViewState["PageNumber"] = value;
}
}
public string SearchCriteria
{
get
{
return Convert.ToString(this.ViewState["SearchCriteria_SearchPage"]);
}
set
{
this.ViewState["SearchCriteria_SearchPage"] = value;
}
}
public int PageCount
{
get
{
if (ViewState["PageCount"] != null)
return Convert.ToInt32(ViewState["PageCount"]);
else
return 0;
}
set
{
ViewState["PageCount"] = value;
}
}
//protected override void OnInit(EventArgs e)
//{
// base.OnInit(e);
// rptPages.ItemCommand += new RepeaterCommandEventHandler(rptPages_ItemCommand);
//}
public void rptPages_ItemCommand(object source, RepeaterCommandEventArgs e)
{
PageNumber = Convert.ToInt32(e.CommandArgument.ToString()) - 1;
Paging();
}
int rq;string ans;
protected void rptPages_ItemDataBound(object source, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
LinkButton lnkPage = (LinkButton)e.Item.FindControl("btnPage");
if (lnkPage.CommandArgument.ToString() == (PageNumber + 1).ToString())
{ lnkPage.CssClass = "btn btn-primary"; }
else {
// LinkButton lnkPage = (LinkButton)e.Item.FindControl("btnPage");
//Label9.Text = lnkPage.CommandArgument.ToString();
AnswerReportProp answer = new AnswerReportProp();
string TestReportID = testreportid;
string TestID = testid;
string SubjectID = subId;
int QSetNo = setNo;
int QuestionNo = Convert.ToInt32(lbQNo.Text);
AnswerReportHandler asvc = new AnswerReportHandler();
answer = asvc.CheckAnsQuestPrac(testreportid, TestID, SubjectID, QSetNo, QuestionNo);
if (answer != null )
{
rq = answer.ReviewQuestion;
if (rq == 1 )
{ lnkPage.BackColor = System.Drawing.Color.Purple; }
else if (rq == 0)
{ lnkPage.BackColor = System.Drawing.Color.Green; }
else { { lnkPage.CssClass = "btn btn-default"; } }
}
else
{
rq = 0;
if (rq == 1)
{ lnkPage.BackColor = System.Drawing.Color.Purple; }
else if (rq == 0)
{ lnkPage.BackColor = System.Drawing.Color.Green; }
else { { lnkPage.CssClass = "btn btn-default"; } }
}
}
}
}
 

Attachment: Capture.zip

Answers (1)