I have getting
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
onprerender="dpCompAnnouncement_PreRender">
private string prevEventDateAnnouncement = "00 xxx 0000";
protected void lstRecentCompanyAnnouncement_ItemDataBound(object sender, ListViewItemEventArgs e)
{
//try
//{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ListViewDataItem item = (ListViewDataItem)e.Item;
string AnnouncementDate = string.Empty;
AnnouncementDate = Convert.ToDateTime(lstRecentCompanyAnnouncement.DataKeys[item.DataItemIndex]["PublishDate"]).ToString("dd MMM yyyy");
if (!prevEventDateAnnouncement.Equals(AnnouncementDate, StringComparison.CurrentCultureIgnoreCase))
{
HtmlTableRow trDate = (HtmlTableRow)e.Item.FindControl("trDate");
HtmlTableCell htc = new HtmlTableCell();
htc.ColSpan = 2;
htc.Attributes.Add("class", "date-hd");
htc.InnerHtml = "" + AnnouncementDate + "";
trDate.Controls.Add((HtmlTableCell)htc);
trDate.Visible = true;
prevEventDateAnnouncement = AnnouncementDate;
}
HiddenField hdNamenDesignation = (HiddenField)e.Item.FindControl("hdnNamenDesignation");
HiddenField hdDescription = (HiddenField)e.Item.FindControl("hdnDescription");
Label lblNamenDesignation = (Label)e.Item.FindControl("lblNamenDesignation");
Label lblCompanyAnn = (Label)e.Item.FindControl("lblCompanyAnn");
if (!string.IsNullOrEmpty(hdNamenDesignation.Value))
{
lblNamenDesignation.Text = hdNamenDesignation.Value;
lblCompanyAnn.Attributes.Add("onmouseover", "javascript:tooltip.show('" + hdDescription.Value.Replace("'", "") + "');");
lblCompanyAnn.Attributes.Add("onmouseout", "javascript:tooltip.hide();");
}
else
{
if (hdDescription.Value.Length > 31)
{
lblNamenDesignation.Text = hdDescription.Value.Substring(0, 30) + "...";
lblCompanyAnn.Attributes.Add("onmouseover", "javascript:tooltip.show('" + hdDescription.Value.Replace("'", "") + "');");
lblCompanyAnn.Attributes.Add("onmouseout", "javascript:tooltip.hide();");
}
}
}
//}
//catch (Exception err)
//{
// Response.Write(err.Message);
//}
}
#endregion
protected void dpCompAnnouncement_PreRender(object sender, EventArgs e)
{
lstComAnn();
}
public void lstComAnn()
{
object[] param = new object[2];
param[0] = "HomePageAnnouncement";
param[1] = DBNull.Value;
lstRecentCompanyAnnouncement.DataSource = objHandler.ExecuteProcedureRtnDT("RB_CompanyAnnouncement", param);
lstRecentCompanyAnnouncement.DataBind();
}

Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Sep 27, 2011, 1:56 AM EDT
Just debug and see the Variable values which has the String Manipulations like replace,substring,......
Error like this may be getting bcoz of the null value or empty value of the string.
Prabhu RajaRank #861 · 2.6K reputationPosted Sep 27, 2011, 3:18 AM EDT
if (hdDescription.Value.Length > 31)
{
lblNamenDesignation.Text = hdDescription.Value.Substring(0, 29) + "...";
lblCompanyAnn.Attributes.Add("onmouseover", "javascript:tooltip.show('" + hdDescription.Value.Replace("'", "") + "');");
lblCompanyAnn.Attributes.Add("onmouseout", "javascript:tooltip.hide();");
}
-------------------------------------------------------------------------------------------
If this post helps you, then mark as "Correct Answer"
Thank You
Mamta MRank #268 · 9.4K reputationPosted Sep 27, 2011, 3:27 AM EDT
AnnouncementDate = Convert.ToDateTime(lstRecentCompanyAnnouncement.DataKeys[item.DataItemIndex]["PublishDate"]).ToString("dd MMM yyyy");
sonal thosar17 reputationPosted Sep 27, 2011, 9:47 PM EDT
I have getting error on this statement
I have getting Announcementdate like this
14 Sep 201114 Sep 2011
Prabhu RajaRank #861 · 2.6K reputationPosted Sep 27, 2011, 10:15 PM EDT
DateTime AnnouncementDate = new DateTime(); //Change AnnouncementDate from String to DateTime
bool isConverted = DateTime.TryParse(lstRecentCompanyAnnouncement.DataKeys[item.DataItemIndex]["PublishDate"].ToString("dd MMM yyyy"), out AnnouncementDate );
------------------------------------------------------------------
If this helps you, then mark as "Correct Answer"
Thank You
sonal thosar17 reputationPosted Sep 27, 2011, 10:51 PM EDT
I have tried
DateTime.TryParse(lstRecentCompanyAnnouncement.DataKeys[item.DataItemIndex]["PublishDate"].ToString("dd MMM yyyy"), out AnnouncementDate);
but now i getting different kind of error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1501: No overload for method 'ToString' takes '1' arguments