⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basegridcontrol.cs

📁 community server 源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
			l.EditFieldCssClass="EditDataField";
			l.EditCommandClientTemplateId="EditCommandTemplate"; 
			l.InsertCommandClientTemplateId="InsertCommandTemplate"; 
			l.AlternatingRowCssClass="AlternatingRow";

		}

		/// <summary>
		/// Auto binds the appropriate styles to rows (except the last row, which must be set manually)
		/// Also replaces any ResourceManager.[Resource Manager Key] values in the HeadingText with the 
		/// appropriate resource text.
		/// </summary>
		protected virtual void ConfigureGridColumnProperties()
		{

			Grid.Levels[0].Columns[0].HeadingCellCssClass = "FirstHeadingCell";
			Grid.Levels[0].Columns[0].DataCellCssClass = "FirstDataCell";

			foreach(CA.GridColumn gc in Grid.Levels[0].Columns)
			{
				if(gc.Visible)
				{
					gc.SortedDataCellCssClass = "SortedDataCell";
					//Allows for mock resource manager calls in heading text
					//eg HeadingText="ResourceManager.CP_Photos_GridCol_Name"
					if(gc.HeadingText.StartsWith("ResourceManager."))
						gc.HeadingText = ResourceManager.GetString(gc.HeadingText.Replace("ResourceManager.",""));

					//gc.TextWrap=true;
			
				}
			}
		}

		/// <summary>
		/// Adds a standard Loading template to the grid
		/// </summary>
		protected virtual void AddGridLoadingTemplate()
		{
			CA.ClientTemplate loadingTemplate = new CA.ClientTemplate();
			loadingTemplate.ID = "Loading";
			loadingTemplate.Text = string.Concat(@"
									<table cellspacing=""0"" cellpadding=""0"" border=""0"">
										<tr>
											<td style=""font-size:10px;"">Loading...&nbsp;</td>
											<td><img src=""", SiteUrls.Instance().LoadingImageUrl , @""" width=""16"" height=""16"" border=""0""></td>
										</tr>
									</table>") ;
			Grid.ClientTemplates.Add(loadingTemplate);
			Grid.LoadingPanelClientTemplateId = loadingTemplate.ID;
			Grid.LoadingPanelPosition = CA.GridRelativePosition.MiddleCenter;

		}

		/// <summary>
		/// Adds the standard published date template to the grid and binds it to the DateDataField column
		/// </summary>
		/// <param name="AuthorURL"></param>
		/// <param name="AuthorDataField"></param>
		/// <param name="DateDataField"></param>
		protected virtual void AddGridPublishedDateTemplate(string AuthorURL, string AuthorDataField, string DateDataField)
		{
			CA.ClientTemplate template = new CA.ClientTemplate();
			template.ID = String.Concat(DateDataField,"DateTemplate");
			template.Text = String.Format(@"
			<table width=""100%"" cellspacing=""0"" cellpadding=""1"" border=""0"">
				<tr>
					<td class=""CellText"" align=""right""> {3} <a style=""color:#595959;"" href='## DataItem.GetMember(""{0}"").Value ##'><b>## DataItem.GetMember(""{1}"").Value ##</b></a></td>
				</tr>
				<tr>
					<td class=""CellText"" align=""right""><font color=""#595959"">## DataItem.GetMember(""{2}"").Value ##</font></td>
				</tr>
			</table>", AuthorURL, AuthorDataField, DateDataField, ResourceManager.GetString("CP_By"));

			Grid.ClientTemplates.Add(template);

			AttachGridColumnClientTemplate(DateDataField, template);

		}

		/// <summary>
		/// Adds a standard Cross / Check Template and binds it to a boolean column in the grid
		/// </summary>
		/// <param name="DataFieldName"></param>
		protected virtual void AddGridCheckMarkTemplate(string DataFieldName)
		{
			CA.ClientTemplate template = new CA.ClientTemplate();
			template.ID = string.Concat("CheckTemplate",DataFieldName) ;
			template.Text = String.Format(@"<img src=""{0}images/## DataItem.GetMember(""{1}"").Value ##.gif"" width=""16"" height=""15"" />", SiteUrls.Instance().Locations["ControlPanel"], DataFieldName);
			
			Grid.ClientTemplates.Add(template);

			CA.GridColumn gc = AttachGridColumnClientTemplate(DataFieldName, template);
			
			//if the DataFieldName was not found this will throw an error
			gc.Width = 65;
			gc.FixedWidth = true;
			gc.Align = CA.TextAlign.Center;
		}

		/// <summary>
		/// Adds an HREF Template to the grid and binds it to the specified column
		/// To support advanced client side databinding, the ## DataItem.GetMember("DataFieldName").Text ##
		/// syntax can be used in the href
		/// </summary>
		/// <param name="Href"></param>
		/// <param name="DataFieldName"></param>
		protected virtual void AddGridHrefTemplate(string Href, string DataFieldName)
		{
			AddGridHrefTemplate(Href, "", DataFieldName);
		}
		protected virtual void AddGridHrefTemplate(string Href, string cssClass, string DataFieldName)
		{
			AddGridHrefTemplate(Href, cssClass, DataFieldName, "");
		}
		protected virtual void AddGridHrefTemplate(string Href, string cssClass, string DataFieldName, string SecondLine)
		{
			CA.ClientTemplate template = new CA.ClientTemplate();
			template.ID = string.Concat("HrefTemplate", DataFieldName);

			string style = "";
			if(!Globals.IsNullorEmpty(cssClass))
				style = string.Concat("class=", cssClass); 
			template.Text = String.Format(@"<a href='{0}' {1}>## DataItem.GetMember(""{2}"").Value ##</a>", Href, style, DataFieldName);

			if(!Globals.IsNullorEmpty(SecondLine))
				template.Text = String.Concat(template.Text, "<br />", SecondLine);

			Grid.ClientTemplates.Add(template);
			
			AttachGridColumnClientTemplate(DataFieldName, template);
		}

		/// <summary>
		/// Adds multiple HREF Templates to the grid and binds them to the specified columns.
		/// Links will be seperated by a specified delimter.
		/// To support advanced client side databinding, the ## DataItem.GetMember("DataFieldName").Text ##
		/// syntax can be used in the href
		/// </summary>
		protected virtual void AddGridHrefTemplate(string[] href, string[] label, string dataFieldToAttach, string delimiter)
		{
			 AddGridHrefTemplate(href, label, new string[href.Length], dataFieldToAttach, delimiter);
		}
		protected virtual void AddGridHrefTemplate(string[] href, string[] label, string[] cssClass, string dataFieldToAttach, string delimiter)
		{
			if (href.Length != label.Length)
				throw new Exception("Parameter array lengths do not match!");

			int lowerBound = href.GetLowerBound(0);

			CA.ClientTemplate template = new CA.ClientTemplate();
			template.ID = string.Concat("HrefTemplate", label[lowerBound]);
			template.Text = "";

			for (int i = lowerBound; i <= href.GetUpperBound(0); i++)
			{
				if (i != lowerBound)
					template.Text += delimiter;

				string style = "";
				if(!Globals.IsNullorEmpty(cssClass[i]))
					style = string.Concat("class=", cssClass[i]); 
				
				template.Text += String.Format(@"<a href='{0}' {1}>{2}</a>", href[i], style, label[i]);
			}

			Grid.ClientTemplates.Add(template);
			AttachGridColumnClientTemplate(dataFieldToAttach, template);
		}

		/// <summary>
		/// Attaches a new ClientTemplate to the specified Grid Column
		/// </summary>
		/// <param name="DataFieldName"></param>
		/// <param name="template"></param>
		/// <returns>A reference to the grid column the template was attached to, or null if the template was not found</returns>
		protected virtual CA.GridColumn AttachGridColumnClientTemplate(string DataFieldName, CA.ClientTemplate template)
		{
			foreach(CA.GridColumn gc in Grid.Levels[0].Columns)
			{
				if(gc.DataField == DataFieldName  && gc.Visible)
				{
					gc.DataCellClientTemplateId = template.ID;
					return gc;
				}
			}
			return null;
		}

		/// <summary>
		/// Builds the standard pager slider template and attaches it to the Grid
		/// </summary>
		/// <param name="TitleDataField">The main title to show in the pager</param>
		protected virtual void AddGridPagerTemplate(string TitleDataField)
		{
			AddGridPagerTemplate(TitleDataField, null, null, null, null);
		}

		/// <summary>
		/// Builds the standard pager slider template and attaches it to the Grid
		/// </summary>
		/// <param name="TitleDataField">The main title to show in the pager</param>
		/// <param name="BoolDataField">Makes a red or green flag or the right based on bool</param>
		protected virtual void AddGridPagerTemplate(string TitleDataField, string BoolDataField)
		{
			AddGridPagerTemplate(TitleDataField, null, null, BoolDataField, null);
		}

		/// <summary>
		/// Builds the standard pager slider template and attaches it to the Grid
		/// </summary>
		/// <param name="TitleDataField">The main title to show in the pager</param>
		/// <param name="UserDataField"></param>
		/// <param name="BoolDataField">Makes a red or green flag or the right based on bool</param>
		protected virtual void AddGridPagerTemplate(string TitleDataField, string UserDataField, string BoolDataField)
		{
			AddGridPagerTemplate(TitleDataField, UserDataField, null, BoolDataField, null);
		}

		/// <summary>
		/// Builds the standard pager slider template and attaches it to the Grid
		/// </summary>
		/// <param name="TitleDataField">The main title to show in the pager</param>
		/// <param name="UserDataField"></param>
		/// <param name="DateDataField"></param>
		/// <param name="BoolDataField">Makes a red or green flag or the right based on bool</param>
		protected virtual void AddGridPagerTemplate(string TitleDataField, string UserDataField, string DateDataField, string BoolDataField)
		{
			AddGridPagerTemplate(TitleDataField, UserDataField, DateDataField, BoolDataField, null);
		}
		
		/// <summary>
		/// Builds the standard pager slider template and attaches it to the Grid
		/// </summary>
		/// <param name="TitleDataField">The main title to show in the pager</param>
		/// <param name="UserDataField">Can Be Null</param>
		/// <param name="DateDataField">Can Be Null</param>
		/// <param name="BoolDataField">Makes a red or green flag or the right based on bool, Can Be Null</param>
		/// <param name="ImageSource">Image to show on the left, Can Be Null</param>
		protected virtual void AddGridPagerTemplate(string TitleDataField, string UserDataField, string DateDataField,string BoolDataField, string ImageSource)
		{
			CA.ClientTemplate sliderTemplate = new CA.ClientTemplate();
			sliderTemplate.ID = "SliderTemplate";

			StringBuilder s = new StringBuilder() ;
			s.Append(@"<table class=""GraySliderPopup"" cellspacing=""0"" cellpadding=""0"" border=""0"">
						<tr>
						<td valign=""top"" style=""padding:5px;"">
						<table width=""100%"" cellspacing=""0"" cellpadding=""0"" border=""0"">
						<tr>
							<td width=""25"" align=""center"" valign=""top"" style=""padding-top:3px;"">");
			
			//Attach the left image (ImageSource) if supplied
			if(Globals.IsNullorEmpty(ImageSource))
				s.Append("&nbsp;");
			else
				s.AppendFormat(@"<img src='## DataItem.GetMember(""{0}"").Value ##'  width=""25"" />",ImageSource);
 
			s.Append(@" </td>
						<td>
							<table cellspacing=""0"" cellpadding=""2"" border=""0"" style=""width:255px;"">
							<tr>");


			s.Append(@"<td><table width=""100%"" cellspacing=""0"" cellpadding=""1"" border=""0"">
                <tr>");
 
			// Attach the UserDataField if Present
			if(Globals.IsNullorEmpty(UserDataField))
				s.Append(@"<td class=""CellText"" align=""right"">&nbsp;</td>");
			else
				s.AppendFormat(@"<td class=""CellText"" align=""right"">## DataItem.GetMember(""{0}"").Value ##</td>",UserDataField);

			s.Append(@"</tr><tr>");
             
			// Attach the DateDataField if Present
			if(Globals.IsNullorEmpty(DateDataField))
				s.Append(@"<td class=""CellText"" align=""right"">&nbsp;</td>");
			else
				s.AppendFormat(@"<td class=""CellText"" align=""right""><font color=""#595959"">## DataItem.GetMember(""{0}"").Value ##</font></td>",DateDataField);
			s.Append(@"</tr></table></td>");

			s.Append(@"</tr>
							<tr>
							<td colspan=""2"">
							<table cellspacing=""0"" cellpadding=""0"" border=""0"" width=""100%"">
							<tr>");

			//Attach the TitleDataField
			s.AppendFormat(@"<td width=""230"" colspan=""2"" style=""font-family:verdana;font-size:11px;font-weight:bold;""><div style=""text-overflow:ellipsis;overflow:hidden;width:250px;""><nobr>## DataItem.GetMember(""{0}"").Value ##</nobr></div></td>", TitleDataField);
			
			s.Append(@"</tr>
							</table>                                    
							</tr>
							</table>    
							</td>
						</tr>
						</table>  
						</td>");
			
			//Attach the BoolDataField for the flag image
			if(Globals.IsNullorEmpty(BoolDataField))
				s.Append(@"<td style=""background-color:#CAC6D4;padding:2px;"" align=""center"">&nbsp;</td>");
			else
				s.AppendFormat(@"<td style=""background-color:#CAC6D4;padding:2px;"" align=""center""><img src=""{0}images/## DataItem.GetMember(""{1}"").Value ##.gif"" width=""12"" height=""12"" border=""0""></td>", SiteUrls.Instance().Locations["ControlPanel"], BoolDataField);
			
			s.AppendFormat(@"</tr>
						<tr>
						<td colspan=""2"" style=""height:14px;background-color:#AABBDD;"">
						<table width=""100%"" cellspacing=""0"" cellpadding=""0"" border=""0"">
						<tr>
							<td style=""padding-left:5px;color:white;font-family:verdana;font-size:10px;"">
							{1} <b>## DataItem.PageIndex + 1 ##</b> {2} <b>## {0}.PageCount ##</b>
							</td>
							<td style=""padding-right:5px;color:white;font-family:verdana;font-size:10px;"" align=""right"">
							{3} <b>## DataItem.Index + 1 ##</b> {2} <b>## {0}.RecordCount ##</b>
							</td>
						</tr>
						</table>  
						</td>
						</tr>
						</table>", Grid.ClientID, ResourceManager.GetString("CP_GridPager_Page") , ResourceManager.GetString("CP_GridPager_Of") , ResourceManager.GetString("CP_GridPager_Item") );

			//Add the slider template
			sliderTemplate.Text = s.ToString(); 
			Grid.ClientTemplates.Add(sliderTemplate);
			Grid.SliderPopupClientTemplateId = sliderTemplate.ID;
			
			//Configure the SliderTemplate and Grid
			Grid.PagerStyle = CA.GridPagerStyle.Slider;
			Grid.SliderHeight=20;
			Grid.SliderWidth=150 ;
			Grid.SliderGripWidth=9 ;
			Grid.SliderPopupOffsetX=20 ;
		}

		/// <summary>
		/// Apply any user settings to the page, this method is usually called after the datasource is
		/// set on the grid in the buildGrid()
		/// </summary>
		protected virtual void ApplyUserSettings()
		{
	
			Grid.ShowHeader = this.ShowHeading;
			Grid.PreExpandOnGroup = this.ExpandGrouping;
			Grid.ShowSearchBox = this.EnableSearchBox;
			if(!this.EnableGrouping || Grid.GroupBy.Length > 0 )
			{
				//This code along with no GroupBy is required to show the header but disable grouping
				Grid.GroupByCssClass = "disabled";
				Grid.GroupByTextCssClass = "disabled";
				Grid.GroupingNotificationTextCssClass = "disabled";
				Grid.Levels[0].AllowGrouping = false;
			}
			else
			{
				Grid.TreeLineImagesFolderUrl= string.Format("{0}images/caimages/lines",  SiteUrls.Instance().Locations["ControlPanel"]); 
				Grid.TreeLineImageWidth=21; 
				Grid.TreeLineImageHeight=19; 
				Grid.IndentCellWidth=22; 
				Grid.GroupByCssClass="GroupByCell"; 
				Grid.GroupByTextCssClass="GroupByText"; 
				Grid.GroupingNotificationTextCssClass="GridHeaderText"; 
				Grid.GroupBySortAscendingImageUrl="group_asc.gif"; 
				Grid.GroupBySortDescendingImageUrl="group_desc.gif"; 
				Grid.GroupBySortImageWidth=10; 
				Grid.GroupBySortImageHeight=10; 
				Grid.Levels[0].AllowGrouping = true;
				Grid.GroupingPageSize=5;
			}

			//Note you must manually set the Grid Recordcount when assigning the DataSource
			if(!this.ShowScrollBar)
				Grid.ShowFooter = (Grid.PageCount > 1);
			
			Grid.Levels[0].AllowReordering = false;

		}

		#endregion

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -