Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
   {
       DataSet ds1 = new DataSet();
       int loggedUserID = Convert.ToInt32(Session["loggedUserID"]);
       List<BOL.UserInfo> userslist = new UserInfos().List();
       BOL.UserInfo loggeduser = userslist.Where(x => x.UserID == loggedUserID).FirstOrDefault();
       List<BOL.MonthlyEvent> Eventlist = new MonthlyEvents().Filter(loggeduser.SUBSIDIARY_CD,loggeduser.CostCenter);
       //ds1 = Eventlist.
       if (!e.Day.IsOtherMonth)
       {
           foreach (DataRow dr in ds1.Tables[0].Rows)
           {
               if ((dr["Event_Date"].ToString() != DBNull.Value.ToString()))
               {
                   DateTime dtEvent = (DateTime)dr["Event_Date"];
                   if (dtEvent.Equals(e.Day.Date))
                   {
                       Label b = new Label();
                       Label d = new Label();
                       b.Font.Size = 8;
                       b.Font.Bold = true;
                       b.ForeColor = System.Drawing.ColorTranslator.FromHtml("#336699");
                       b.Text = dr["EventTitle"].ToString();
                       //   d.Text = dr["description"].ToString();
                       Literal lineBreak = new Literal();
                       lineBreak.Text = "<BR/><BR/>";
                       e.Cell.Controls.Add(lineBreak);
                       //e.Cell.Controls.Add(b);
                       System.Web.UI.HtmlControls.HtmlGenericControl Link = new
                       System.Web.UI.HtmlControls.HtmlGenericControl();
                       Link.TagName = "a";
                       Link.InnerText = dr["EventTitle"].ToString();
                       //   Link.InnerText = dr["description"].ToString();
                       Literal id = new Literal();
                       Label c = new Label();
                       c.Text = e.Day.Date.ToString("yyyy-MM-dd");
                       //set the href value to the javascript function to select the date
                       string myContent = dr["Event_Description"].ToString().Trim().Replace("'", "%2527").Replace("&", "%2526").Replace("+", "%252b");
                       //string myContent = "test";
                       string myTitle = dr["EventTitle"].ToString().Trim();
                       Link.Attributes.Add("href", "javascript:window.location.href=('Event_Edit.aspx?eventdate=" + c.Text + "&title=" + Server.UrlEncode(myTitle) + "&content=" + Server.UrlEncode(myContent) + "');");

                       //set the color of the link
                       Link.Attributes.Add("style", "color:#336699;");

                       //add our link control to the day
                       e.Cell.Controls.Add(Link);
                   }
               }
           }
       }
   }


i get the query result from
C#
MonthlyEvents().Filter(loggeduser.SUBSIDIARY_CD,loggeduser.CostCenter);

how to assign ds1 = my query result?

What I have tried:

ds1 = Eventlist ,but not working..
Posted
Updated 26-Jun-16 19:55pm
v2

1 solution

you cannot assign a Generic List into a DataSet or a DataTable,
use these utilities to convert List to DataSet
transform a List<t> into a DataSet? [^]
Convert generic list to dataset in C# - Stack Overflow[^]

or using Manual Conversion:

C#
public class MyType
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string Address { get; set; }
}


Manual Conversion
C#
List<MyType> listMyType = new List<MyType>();
       listMyType.Add(new MyType() { ID = 1, Name = "aa", Address = "ind" });
       listMyType.Add(new MyType() { ID = 1, Name = "bb", Address = "uk" });
       DataSet ds = new DataSet();

       DataTable dt = new DataTable();
       dt.Columns.Add("ID", typeof(int));
       dt.Columns.Add("Name", typeof(string));
       dt.Columns.Add("Address", typeof(string));
       foreach (var item in listMyType)
           dt.Rows.Add(item.ID, item.Name, item.Address);

       ds.Tables.Add(dt);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900