sharepoint 自定义字段实现省市联动

最后实现效果如下:

设置栏如下:

解决方案结构如下:


fldtypes_RoyCustomField.xml 内容如下:

<? xml version="1.0" encoding="utf-8"  ?>
< FieldTypes >
  
< FieldType >
    
< Field  Name ="TypeName" > RoyCustomField </ Field >
    
< Field  Name ="ParentType" > Text </ Field >
    
< Field  Name ="TypeDisplayName" > RoyCustomField </ Field >
    
< Field  Name ="TypeShortDescription" > RoyCustomField </ Field >
    
< Field  Name ="UserCreatable" > TRUE </ Field >
    
< Field  Name ="FieldTypeClass" > RoyCustomField.RoyCustomField,$SharePoint.Project.AssemblyFullName$ </ Field >
  
</ FieldType >
</ FieldTypes >


RoyCustomField.cs 内容如下:

using  Microsoft.SharePoint;
using  Microsoft.SharePoint.WebControls;
using  System.Web.UI.WebControls;
using  System.Web.UI;
using  System;
namespace  RoyCustomField
{
    
public   class  RoyCustomField : SPFieldText
    {
        
public  RoyCustomField(SPFieldCollection field,  string  strFieldName)
            : 
base (field, strFieldName)
        {
        }
        
public  RoyCustomField(SPFieldCollection field,  string  strFieldName,  string  strDispName)
            : 
base (field, strFieldName, strDispName)
        {
        }
            

        
public   override  BaseFieldControl FieldRenderingControl
        {
            
get
            {
                BaseFieldControl fc 
=   new  RoyText();
                fc.FieldName 
=   this .InternalName;
                
return  fc;
            }
        }
    }


    
public   class  RoyText : BaseFieldControl
    {

        
private  DropDownList _ddlProvince;
        
private  DropDownList _ddlCity;
        
#region  Province of autoPostBack
        
void  Province_SelectedIndexChanged( object  sender, EventArgs e)
        {
            _ddlCity.Items.Clear();
            
if  (_ddlProvince.SelectedValue.ToString()  ==   " 河北省 " )
            {
                _ddlCity.Items.Add(
new  ListItem( " 石家庄市 " " 石家庄市 " ));
            }
            
else   if  (_ddlProvince.SelectedValue.ToString()  ==   " 山东省 " )
            {
                _ddlCity.Items.Add(
new  ListItem( " 济南市 " " 济南市 " ));
            }
            
else
            {
                _ddlCity.Items.Add(
new  ListItem( " 北京市 " " 北京市 " ));
            }
        }
        
#endregion
        
protected   override   void  CreateChildControls()
        {

            
base .CreateChildControls();
            
this .TemplateContainer.FindControl( " _ddlProvince " );
            _ddlProvince 
=   new  DropDownList();
            _ddlProvince.Items.Add(
new  ListItem( " 河北省 " " 河北省 " ));
            _ddlProvince.Items.Add(
new  ListItem( " 山东省 " " 山东省 " ));

            _ddlProvince.AutoPostBack 
=   true ;
            _ddlProvince.SelectedIndexChanged 
+=  Province_SelectedIndexChanged;
            
this .Controls.Add(_ddlProvince);
            
this .Controls.Add( new  LiteralControl( "  -  " ));
            
this .TemplateContainer.FindControl( " _ddlCity " );
            _ddlCity 
=   new  DropDownList();
            _ddlCity.Items.Add(
new  ListItem( " 石家庄市 " " 石家庄市 " ));
            _ddlCity.Items.Add(
new  ListItem( " 济南市 " " 济南市 " ));
            
this .Controls.Add(_ddlCity);
        }

        
        
public   override   object  Value
        {
            
get
            {
                
this .EnsureChildControls();
                
return  _ddlProvince.Text + " - " + _ddlCity.Text;
            }
            
set
            {
                
string  fv  =  ( string ) this .ItemFieldValue;
                
if  (fv.Contains( " - " ))
                {
                    
string [] all  =  fv.Split( ' - ' );
                    _ddlProvince.Text 
=  all[ 0 ];
                    _ddlCity.Text 
=  all[ 1 ];
                }
            }
        }
    }
}


注意事项:

1.xml的文件名必须以fldtypes_开头,否则不能识别。

2.如果要设置默认值请Override DefaultValue,如果要验证格式是否正确请Override GetValidatedString。


本文参考:http://www.cnblogs.com/Roy_Cao/archive/2012/08/14/2637542.html 

转载于:https://www.cnblogs.com/zzkun/p/4481780.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
自定义 SharePoint 登录页面的后台代码,需要进行以下步骤: 1. 创建一个新的 SharePoint 项目,并添加一个新的 Application Page。 2. 在 Application Page 中添加一个 ASP.NET 登录控件,以便用户可以输入其凭据。 3. 使用 SharePoint 对象模型或 CSOM(客户端对象模型)来验证用户凭据。 4. 如果凭据有效,则将用户重定向到 SharePoint 站点的默认页面。 以下是一个简单的示例代码,可以作为参考: ```c# using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using System; using System.Web.UI.WebControls; namespace CustomLoginPage.Layouts.CustomLoginPage { public partial class Login : LayoutsPageBase { protected void Page_Load(object sender, EventArgs e) { // Check if the user is already authenticated if (SPContext.Current.Web.CurrentUser != null) { // Redirect to the default page SPUtility.Redirect(SPContext.Current.Web.Url, SPRedirectFlags.Default, HttpContext.Current); } } protected void LoginButton_Click(object sender, EventArgs e) { // Authenticate the user using SharePoint object model or CSOM bool isAuthenticated = AuthenticateUser(UsernameTextBox.Text, PasswordTextBox.Text); if (isAuthenticated) { // Redirect to the default page SPUtility.Redirect(SPContext.Current.Web.Url, SPRedirectFlags.Default, HttpContext.Current); } else { // Display an error message ErrorLabel.Text = "Invalid username or password"; } } private bool AuthenticateUser(string username, string password) { // TODO: Authenticate the user using SharePoint object model or CSOM // You can use the following code to authenticate the user using SharePoint object model: //using (SPSite site = new SPSite(SPContext.Current.Web.Url)) //{ // using (SPWeb web = site.OpenWeb()) // { // if (web.Site.WebApplication.UseClaimsAuthentication) // { // return SPClaimsUtility.AuthenticateFormsUser( // Context.Request.UrlReferrer, // username, // password); // } // else // { // return web.Authenticate(username, password); // } // } //} // Replace the above code with your own authentication logic return true; } } } ``` 请注意,此示例仅演示了如何在后台代码中验证用户凭据。要完全自定义 SharePoint 登录页面,您还需要编写自己的 HTML 和 CSS 代码,以及处理其他相关的逻辑。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值