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();
}
sonal thosarPosted Sep 28, 2011, 2:51 AM
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
Prabhu RajaPosted Sep 28, 2011, 2:15 AM
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 thosarPosted Sep 28, 2011, 1:47 AM
I have getting error on this statement
I have getting Announcementdate like this
14 Sep 201114 Sep 2011
Mamta MPosted Sep 27, 2011, 7:27 AM
AnnouncementDate = Convert.ToDateTime(lstRecentCompanyAnnouncement.DataKeys[item.DataItemIndex]["PublishDate"]).ToString("dd MMM yyyy");
Prabhu RajaPosted Sep 27, 2011, 7:18 AM
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
Jaganathan BantheswaranPosted Sep 27, 2011, 5:56 AM
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.