How to put a radcombobox or any 3rd party controls inside infragistic ultrawebgrid


This code shows how to put radcombox or any 3rd party controls inside Infragistic ultrawebgrid.

Description :



Some days back I faced a problem that I needed a radcombobox inside a infragistic ultrawebgrid control.
I thought it is quite impossible to put one 3rd paty contyrols inside another 3rd party controls.Then finally i solved that problem.

The ultrawebgrid have ethier own column properties for creating a column of checkbox type or dropdown type or hidden column or only column .

Example:


UltraGridColumn checkSend = new UltraGridColumn();
checkSend.Header.Caption = sendHeader;
checkSend.Type = ColumnType.CheckBox;


Here column type is checkbox .You can make it dropdown also.But my requirement was to have a radcombox box.
To put radcombox or any combobox or 3rd party controls you can use this code.

First create a template column and assign a key value .



TemplatedColumn col = new TemplatedColumn();
col.Key = "Pharamcy";
col.HeaderText = "PharmacyList";
col.Width = Unit.Percentage(12);

PlaceHolderTemplate temp = new PlaceHolderTemplate();
col.CellTemplate = temp;
//add that column to the web grid

UltragridPres.Bands[0].Columns.Insert(UltragridPres.Bands[0].Columns.Count, col);



Then create a class to describe the structure of the column template and that class must implement ITemplate interface.

See this class :




public class PlaceHolderTemplate : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
CellItem cellitem = (CellItem)container;
//Declare the control (or controls) you wish to put into the column template
RadComboBox PharamacyList = new RadComboBox();//dyanamic create a radacombobox .you can craete you own controls
cellitem.Controls.Add(PharamacyList); //Adds the control to the column template for this row
//cellitem.Cell.AllowEditing = AllowEditing.No; //Don't want to actually be able to edit the cell, just
}
}


Then create the function for creating controls.Here we set the ID property for the controls that we added in the instantiatein method,and attach an event handler for one of the control's events.This step is required to hook up the event handler. All other properties should be set in the InitializeRow event.If you are not setting a server-side event handler for the control, you do not need to override the CreatChildControls method, and should do everything in the InitialzieRow event.Since we have access to the grid object, we again have the opportunity to set properties based on a number of criteria, including the value of another cell in the row.You should ensure that you get the right controls that you put into the specific rows in the instantiate in. Otherwise you will get an InvalidCast exception. In this example, we put an combox into each row with "Phramacy" value.


protected override void CreateChildControls()
{

Infragistics.WebUI.UltraWebGrid.TemplatedColumn col = (TemplatedColumn)UltragridPres.Columns.FromKey("Pharamcy");

base.CreateChildControls();

for (int i = 0; i < UltragridPres.Rows.Count; i++)
{
RadComboBox PharamacyList = (RadComboBox)((CellItem)col.CellItems[i]).Controls[0];
PharamacyList.ID = "PharamacyList";//id
PharamacyList.Width = Unit.Pixel(80);
PharamacyList.Height = Unit.Pixel(80);
PharamacyList.ExpandAnimation.Type = AnimationType.OutSine;
PharamacyList.DropDownWidth = Unit.Pixel(150);
// add clientside event and that function must be declared at client end
PharamacyList.OnClientDropDownClosed = "OnClientDropDownClosed";
PharamacyList.OnClientItemsRequesting = "OnClientItemsRequesting";
PharamacyList.OnClientDropDownOpening = "OnClientDropDownOpening";
PharamacyList.HighlightTemplatedItems = true;
PharamacyList.ShowMoreResultsBox = true;
PharamacyList.EnableLoadOnDemand = true;
PharamacyList.Skin = "Hay";
PharamacyList.BackColor = System.Drawing.ColorTranslator.FromHtml("#EDFBE1");
PharamacyList.NoWrap = true;
PharamacyList.EmptyMessage = "Type to search ";//set empty message
//add handler to populate data when item requested
PharamacyList.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(PharamacyList_ItemsRequested);
}
}


The item request event of combobox:



protected void PharamacyList_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
RadComboBox ob = (RadComboBox)o;
ob.Items.Clear();
string sqlSelectCommand = //your query
then create a datatable
DataSet ds = SqlHelper.ExecuteDataset(new Connection().GetCon, CommandType.Text, sqlSelectCommand);
DataTable dtAllData = ds.Tables[0];
ob.DataTextField = "NAME";
ob.DataValueField = "NO";
ob.DataSource = dtAllData;
ob.DataBind();
}


Ensures that the TemplatedColumn is properly instantiated.So add this event



private void UltragridPres_TemplatedColumnRestored(object sender, Infragistics.WebUI.UltraWebGrid.ColumnEventArgs e)
{
if (((TemplatedColumn)e.Column).CellTemplate == null)
{
((TemplatedColumn)e.Column).CellTemplate = new PlaceHolderTemplate();
}
}
}
}


This UltragridPres_TemplatedColumnRestored method must be invoked in OnInit event.So add this eventhandler in the OnInit event.

See below code:


override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{

this.UltragridPres.TemplatedColumnRestored += new Infragistics.WebUI.UltraWebGrid.TemplatedColumnRestoredEventHandler(this.UltragridPres_TemplatedColumnRestored);

}



You must need the code for creating ultrawebgrid:


Metatag:


<%@ Register Assembly="Infragistics35.WebUI.UltraWebGrid.v8.2, Version=8.2.20082.1000, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.WebUI.UltraWebGrid" TagPrefix="igtbl" %>


Ultrawebgrid controls:

<igtbl:UltraWebGrid ID="UltragridPres" runat="server" Width="100%">
<Bands>
<igtbl:UltraGridBand>
<AddNewRow View="NotSet" Visible="NotSet">
</AddNewRow>
</igtbl:UltraGridBand>
</Bands>
<DisplayLayout AllowColSizingDefault="Free" AllowDeleteDefault="Yes" ScrollBarView="Vertical"
AllowUpdateDefault="Yes" BorderCollapseDefault="Separate" Name="UltraWebGrid1"
RowHeightDefault="20px" SelectTypeRowDefault="Single" TableLayout="Fixed" Version="4.00"
AllowAddNewDefault="Yes" SelectTypeCellDefault="Single" CellClickActionDefault="RowSelect"
CompactRendering="False" StationaryMargins="Header" ColHeadersVisibleDefault="Yes">
<FrameStyle BackColor="Window" BorderColor="InactiveCaption" Font-Names="Microsoft Sans Serif"
Font-Size="8.25pt" Width="100%" Height="200px">
</FrameStyle>
<Pager MinimumPagesForDisplay="2">
<PagerStyle BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">
<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />
</PagerStyle>
</Pager>
<EditCellStyleDefault BorderStyle="None" BorderWidth="0px">
</EditCellStyleDefault>
<FooterStyleDefault BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">
<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />
</FooterStyleDefault>

<HeaderStyleDefault Height="0px" BackColor="#006699" BorderWidth="1px" BorderStyle="Solid"
VerticalAlign="Middle" HorizontalAlign="Left" Font-Bold="true" ForeColor="White">
<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" ColorBottom="Gray"
WidthTop="1px" ColorRight="Gray" />
</HeaderStyleDefault>
<RowSelectorStyleDefault BorderColor="#006699">
<BorderDetails StyleBottom="None" StyleLeft="None" StyleRight="None" StyleTop="Solid" />
</RowSelectorStyleDefault>
<RowStyleDefault BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" Font-Names="Microsoft Sans Serif"
Font-Size="8.25pt" Cursor="Hand">
<Padding Left="3px" />
<BorderDetails ColorLeft="Window" ColorTop="Window" />
</RowStyleDefault>
<RowAlternateStyleDefault CssClass="gridAlternateItem">
</RowAlternateStyleDefault>
<SelectedRowStyleDefault CssClass="girdSelectedItem" Cursor="Hand">
</SelectedRowStyleDefault>
<ActivationObject BorderColor="" BorderWidth="">
</ActivationObject>
</DisplayLayout>
</igtbl:UltraWebGrid>


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: