民工皇帝

龙在沙滩被虾戏,虎落平阳被犬欺. 虎伏深山听风啸,龙卧浅滩等海潮. 海到尽头天做岸,山登绝顶我为峰. 如日东山能在起,大鹏展翅恨天低。 谁无虎落平阳日,待我东山再起时. 有朝一日龙得水,必令长江水倒流. 有朝一日凤回巢,必让长城永不倒. 有朝一日虎归山,必要血染半边天. 有朝一日狮入林,我要气吼山河震. 有朝一日游地府,我让地府底朝天. 有朝一日游天边,众神跪在我身边. 有朝一日凤翔天,我要天下尽我鸣. 有朝一日我出头,我要天下唯我尊. 天下英雄出我辈,一入江湖岁月摧. 宏图霸业谈笑中,不胜人生一场醉

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

1.SPFieldType.Choice

   读取选项里所有的值:

               SPSite sites = SPContext.Current.Site;
                SPWeb web = sites.OpenWeb();
                SPList list = web.Lists.TryGetList("客户信息");
                SPListItem item=list.GetItemById(Int32.Parse(this.strCID));

                SPFieldChoice fieldChoice = list.Fields["行业"] as SPFieldChoice;
                StringCollection str = fieldChoice.Choices;

     str里就是下来列表里的所有值。

      读取当前选中的值  string s=listitem["行业"].ToString();

  设置下拉列表的值:

                SPSite sites = SPContext.Current.Site;
                SPWeb web = sites.OpenWeb();
                SPList list = web.Lists.TryGetList("客户信息");

                SPFieldChoice fieldChoice = list.Fields["行业"] as SPFieldChoice;
                StringCollection str = fieldChoice.Choices;
                        if (!str.Contains(“123”))
                        {
                            str.Add(strValue);
                        }
                        listitem[“行业”] = “123”;

2.SPFieldType.MultiChoice

  读取多选框里的值

                SPSite sites = SPContext.Current.Site;
                SPWeb web = sites.OpenWeb();
                SPList list = web.Lists.TryGetList("客户信息");
                SPListItem item=list.GetItemById(Int32.Parse(this.strCID));

                SPFieldMultiChoice mChoice = list.Fields["标签"] as SPFieldMultiChoice;

                 foreach (string strItem in mChoice.Choices)
                {
                  Response.Write( strItem );         

                }

设置内容:

                        SPFieldMultiChoice mChoice = list.Fields[fieldTitle] as SPFieldMultiChoice;
                        StringCollection str = mChoice.Choices;
                        if (!str.Contains(strValue))
                        {
                            str.Add(strValue);
                        }
                        listitem[fieldTitle] = strValue;

3.SPFieldType.URL

   

读取

SPFieldUrl fieldUrl = (SPFieldUrl)item.Fields["URL"];
SPFieldUrlValue value = (SPFieldUrlValue)fieldUrl.GetFieldValue(item["URL"].ToString());
Console.WriteLine(value.Description);

Console.WriteLine(value.Url);

 

 value.Url = "http://www.126.com";
 value.Description = "126";
 fieldUrl.Update();
           

或者更简单的方法:

SPFieldUrlValue value = new SPFieldUrlValue(item["URL"].ToString());
       Console.WriteLine(value.Description);
       Console.WriteLine(value.Url);

 

设置

 using (SPSite site = SPContext.Current.Site)
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["mosstestchoices"];

                    SPListItem item = list.GetItemById(3);
                   
                    SPFieldUrlValue spfv = new SPFieldUrlValue(item["myhyperlink"].ToString());
                    spfv.Url = "http://www.baidu.com";
                    spfv.Description = "new description";
                    item["myhyperlink"] = spfv.ToString();
                    item.Update();

                }

            }

 

    

    

posted on 2011-11-17 15:45  民工皇帝  阅读(549)  评论(0编辑  收藏  举报