本文介绍了Asp.net Web表单将数据集分配给存储过程查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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从



i get the query result from

MonthlyEvents().Filter(loggeduser.SUBSIDIARY_CD,loggeduser.CostCenter);



如何分配ds1 =我的查询结果?



我的尝试:



ds1 =事件列表,但没有工作..


how to assign ds1 = my query result?

What I have tried:

ds1 = Eventlist ,but not working..

推荐答案

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










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);


这篇关于Asp.net Web表单将数据集分配给存储过程查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 04:32