Help with Repeater Control

Posted by Kpoudyal2010 under ASP.NET on 12/9/2011 | Points: 10 | Views : 925 | Status : [Member] | Replies : 3
Hello .Net Gurus


I need help in getting keyword new whenever new records added in
the Communication table I am displaying newly added communication items in
repeater control and I want to display that item as newly added for 36 hours
from the published date, any help would be appreciated.

Thank you,
<asp:Repeater ID ="rptItems" runat ="server" >
<HeaderTemplate >
<h1><span>Blue</span>Updates</h1>
</HeaderTemplate>
<ItemTemplate >
<ul id="subnavigation1">
<li>
<asp:HyperLink ID ="hyper1" runat ="server" NavigateUrl='<%#Eval("Communication_id","~/DetailsView.aspx?Communication_id={0}") %>' >
<%#DataBinder.Eval(Container.DataItem,"Communication_Title")%></asp:HyperLink>
</li>
</ul>
</ItemTemplate>
</asp:Repeater>

private void LoadData()
{

// using (OracleConnection conn = new OracleConnection(Connect))
using(SqlConnection conn = new SqlConnection(Connect))
{
try
{
conn.Open();
string query = "SELECT * FROM COMMUNICATIONS order by communication_id desc";
SqlDataAdapter da = new SqlDataAdapter(query, conn);
// OracleDataAdapter da = new OracleDataAdapter(query, conn);
DataTable dt = new DataTable();
da.Fill(dt);
conn.Close();
PagedDataSource pgitems = new PagedDataSource();
DataView dv = new DataView(dt);
pgitems.DataSource = dv;
pgitems.AllowPaging = true;
pgitems.PageSize = 5;
pgitems.CurrentPageIndex = PageNumber;

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 = pages;
rptPages.DataBind();
}

}

else

rptPages.Visible = false;
rptItems.DataSource = pgitems;
rptItems.DataBind();
}

catch(Exception ex)
{
Response.Redirect("Error.aspx");

}
}

}




Responses

Posted by: SheoNarayan on: 12/9/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Its simple, just create a common function something like GetNewFlash(DateTime postedDateTime)
and in this, find out number of days passed from the postedDate and it its less than 2 or 4 (whatever you decide) return "New" otherwise return empty.

Call this function inside ItemTemplate.

Hope this helps.

thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Kpoudyal2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kpoudyal2010 on: 12/9/2011 [Member] Starter | Points: 25

Up
0
Down
How to call function inside ItemTemplate ? Do you have any
sample line of code ?
Thank you sir


Kpoudyal2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Krishna17117 on: 12/10/2011 [Member] Starter | Points: 25

Up
0
Down
Create 3 fields 1 for the item name 2 for the date when it is uploaded three for the current current date - your required date and time
Then compare uploaded date and your required date if it is lessthan then the item is new if it is greater than then the item is old
EX:
My Item is Apple 4s
uploaded Date Time is 10/12/2011 1:25 PM
your required time is 3 days
Then the item is Like this I am assuming Table as Items

SELECT Item From Items
IF(DateTime.Now()-UploadedDate < 3)
Item is New

Else Item is Old

you can use bit for New and Old



Kpoudyal2010, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response