Hi,
I need help with sample code on migrating the following events. Sample code attached below.
InitializeLayout
TemplatedColumnRestored
InitializeRow using templated columns
Thanks for your help.
protected void wbgData_InitializeLayout(object sender, LayoutEventArgs e)
//bool addABlank = false;
switch (_reportID)
{
case "DDC":
//this.wbgData.DisplayLayout.HeaderStyleDefault.HorizontalAlign = HorizontalAlign.Center;
//this.wbgData.DisplayLayout.HeaderStyleDefault.VerticalAlign = VerticalAlign.Middle;
// All the Headers for bound columns initialize to OriginX = 0. Since we want them
// to appear below the added column headers we are going to need to move them down a level
foreach (Infragistics.WebUI.UltraWebGrid.UltraGridColumn c in e.Layout.Bands[0].Columns)
c.Header.RowLayoutColumnInfo.OriginY = 1;
}
// now add an unbound header
Infragistics.WebUI.UltraWebGrid.ColumnHeader ch = new Infragistics.WebUI.UltraWebGrid.ColumnHeader(true);
ch.Caption = "Scheduled To Be Delivered";
ch.Style.HorizontalAlign = HorizontalAlign.Center;
ch.Style.VerticalAlign = VerticalAlign.Middle;
// set the origin to be on the top most level of the header
ch.RowLayoutColumnInfo.OriginY = 0;
// set the newly added column to be in the correct location
ch.RowLayoutColumnInfo.OriginX = 2;
// extend the newly added header over 6 columns
ch.RowLayoutColumnInfo.SpanX = 6;
// add an image to the header object.
//ch.Image.Url = "./images/bankingbtn.gif";
//ch.Image.AlternateText = "Employee Name Grouping";
// add the header into the header layout
e.Layout.Bands[0].HeaderLayout.Add(ch);
break;
default:
protected void wbgData_TemplatedColumnRestored(object sender, ColumnEventArgs e)
if (((TemplatedColumn)e.Column).CellTemplate == null)
((TemplatedColumn)e.Column).CellTemplate = new PlaceHolderTemplate();
//protected void wbgData_InitializeRow(object sender, RowEventArgs e) protected void wbgData_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e) { UltraWebGrid grid = sender as UltraWebGrid; TemplatedColumn tc; CellItem ci; LinkButton lnk;
string s, strTrackingNum;
//Switch on Templated column id switch (_reportID) { case "DDC": tc = (TemplatedColumn)e.Row.Cells.FromKey("DDC").Column; ci = (CellItem)tc.CellItems[e.Row.Index]; lnk = (LinkButton)ci.FindControl("LinkButton1"); if (lnk != null) { //int i = 0; lnk.Text = tblShipment.Rows[e.Row.Index][1].ToString(); lnk.ID = _arrLnkId[e.Row.Index];
lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "');"; //lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "','DDC');"; //lnk.Attributes.Add("onClick", "buttonClick('"tblShipment.Rows[e.Row.Index][1].ToString()"');"); //lnk.Attributes["onclick"] = "javascript:buttonClick('" + _oDr.GetString(i - 1).Trim() + "');"; lnk.Attributes["onmouseover"] = "this.style.color=\'#ff0000\'"; lnk.Attributes["onmouseout"] = "this.style.color=\'#000000\'"; lnk.ForeColor = Color.Black; lnk.Click += new EventHandler(this.lnk_Click); //lnk.ID = _reportDate;
tc = (TemplatedColumn)e.Row.Cells.FromKey("DDCARG").Column; ci = (CellItem)tc.CellItems[e.Row.Index]; lnk = (LinkButton)ci.FindControl("LinkButton1"); if (lnk != null) { //int i = 0; lnk.Text = tblShipment.Rows[e.Row.Index][2].ToString(); if (lnk.Text == null || lnk.Text == "" || lnk.Text == "0" || lnk.Text == "N/A") { lnk.Enabled = false; } else { lnk.Enabled = true; } lnk.ID = _arrLnkId[e.Row.Index] + "ARG" + tblShipment.Rows[e.Row.Index][1].ToString(); //tc.Key; lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "');"; //lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "','DDC');"; //lnk.Attributes.Add("onClick", "buttonClick('"tblShipment.Rows[e.Row.Index][1].ToString()"');"); //lnk.Attributes["onclick"] = "javascript:buttonClick('" + _oDr.GetString(i - 1).Trim() + "');"; lnk.Attributes["onmouseover"] = "this.style.color=\'#ff0000\'"; lnk.Attributes["onmouseout"] = "this.style.color=\'#000000\'"; lnk.ForeColor = Color.Black; lnk.Click += new EventHandler(this.lnk_Click); //lnk.ID = _reportDate;
tc = (TemplatedColumn)e.Row.Cells.FromKey("DDCUPS").Column; ci = (CellItem)tc.CellItems[e.Row.Index]; lnk = (LinkButton)ci.FindControl("LinkButton1"); if (lnk != null) { //int i = 0; lnk.Text = tblShipment.Rows[e.Row.Index][4].ToString(); if (lnk.Text == null || lnk.Text == "" || lnk.Text == "0" || lnk.Text == "N/A") { lnk.Enabled = false; } else { lnk.Enabled = true; } lnk.ID = _arrLnkId[e.Row.Index] + "UPS" + tblShipment.Rows[e.Row.Index][1].ToString();
//tc.Key; lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "');"; //lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "','DDC');"; //lnk.Attributes.Add("onClick", "buttonClick('"tblShipment.Rows[e.Row.Index][1].ToString()"');"); //lnk.Attributes["onclick"] = "javascript:buttonClick('" + _oDr.GetString(i - 1).Trim() + "');"; lnk.Attributes["onmouseover"] = "this.style.color=\'#ff0000\'"; lnk.Attributes["onmouseout"] = "this.style.color=\'#000000\'"; lnk.ForeColor = Color.Black; lnk.Click += new EventHandler(this.lnk_Click); //lnk.ID = _reportDate;
tc = (TemplatedColumn)e.Row.Cells.FromKey("DDCALL").Column; ci = (CellItem)tc.CellItems[e.Row.Index]; lnk = (LinkButton)ci.FindControl("LinkButton1"); if (lnk != null) { //int i = 0; lnk.Text = tblShipment.Rows[e.Row.Index][6].ToString(); if (lnk.Text == null || lnk.Text == "" || lnk.Text == "0" || lnk.Text == "N/A") { lnk.Enabled = false; } else { lnk.Enabled = true; }
lnk.ID = _arrLnkId[e.Row.Index] + "ALL" + tblShipment.Rows[e.Row.Index][1].ToString();
} break; case "DDCTL": tc = (TemplatedColumn)e.Row.Cells.FromKey("DDCTL").Column; ci = (CellItem)tc.CellItems[e.Row.Index]; lnk = (LinkButton)ci.FindControl("LinkButton2"); if (lnk != null) { lnk.Text = tblShipment.Rows[e.Row.Index][1].ToString(); lnk.ID = _arrLnkId[e.Row.Index]; lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "');"; //lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "','DDCTL');"; lnk.Attributes["onmouseover"] = "this.style.color=\'#ff0000\'"; lnk.Attributes["onmouseout"] = "this.style.color=\'#000000\'"; lnk.ForeColor = Color.Black; lnk.Click += new EventHandler(this.lnk_Click);
tc = (TemplatedColumn)e.Row.Cells.FromKey("DDCTLDET").Column; ci = (CellItem)tc.CellItems[e.Row.Index]; lnk = (LinkButton)ci.FindControl("LinkButton2"); if (lnk != null) { lnk.Text = tblShipment.Rows[e.Row.Index][3].ToString();
if (_arrLnkId[e.Row.Index].Substring(6,3) == "ARG") //DDCTL0ARG000 { //Append TL lnk.ID = _arrLnkId[e.Row.Index] + tblShipment.Rows[e.Row.Index][1].ToString(); } else if (_arrLnkId[e.Row.Index].Substring(7, 3) == "ARG") //DDCTL10ARG000 { //Append TL lnk.ID = _arrLnkId[e.Row.Index] + tblShipment.Rows[e.Row.Index][1].ToString(); }
if (_arrLnkId[e.Row.Index].Substring(6, 3) == "ARN") //DDCTL0ARN000 { //Append TL lnk.ID = _arrLnkId[e.Row.Index] + tblShipment.Rows[e.Row.Index][1].ToString(); } else if (_arrLnkId[e.Row.Index].Substring(7, 3) == "ARN") //DDCTL10ARN000 { //Append TL lnk.ID = _arrLnkId[e.Row.Index] + tblShipment.Rows[e.Row.Index][1].ToString(); } //End Anil Madan
else if (_arrLnkId[e.Row.Index].Substring(6, 3) == "UPS") //DDCTL0UPS003 { //Append TL lnk.ID = _arrLnkId[e.Row.Index] + "00000000"; } else if (_arrLnkId[e.Row.Index].Substring(7, 3) == "UPS") //DDCTL10UPS003 { //Append TL lnk.ID = _arrLnkId[e.Row.Index] + "00000000"; }
else if (_arrLnkId[e.Row.Index].Substring(6, 3) == "UPN") //DDCTL0UPN003 { //Append TL lnk.ID = _arrLnkId[e.Row.Index] + "00000000"; } else if (_arrLnkId[e.Row.Index].Substring(7, 3) == "UPN") //DDCTL10UPN003 { //Append TL lnk.ID = _arrLnkId[e.Row.Index] + "00000000"; }
lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "');"; //lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "','DDCTL');"; lnk.Attributes["onmouseover"] = "this.style.color=\'#ff0000\'"; lnk.Attributes["onmouseout"] = "this.style.color=\'#000000\'"; lnk.ForeColor = Color.Black; lnk.Click += new EventHandler(this.lnk_Click);
} break;
case "DDCTLV": tc = (TemplatedColumn)e.Row.Cells.FromKey("DDCTLV").Column; ci = (CellItem)tc.CellItems[e.Row.Index]; lnk = (LinkButton)ci.FindControl("LinkButton3"); if (lnk != null) { //int i = 0; lnk.Text = tblShipment.Rows[e.Row.Index][0].ToString(); lnk.ID = _arrLnkId[e.Row.Index];
lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "');"; //lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "','DDCTLV');"; //lnk.Attributes.Add("onClick", "buttonClick('"tblShipment.Rows[e.Row.Index][1].ToString()"');"); //lnk.Attributes["onclick"] = "javascript:buttonClick('" + _oDr.GetString(i - 1).Trim() + "');"; lnk.Attributes["onmouseover"] = "this.style.color=\'#ff0000\'"; lnk.Attributes["onmouseout"] = "this.style.color=\'#000000\'"; lnk.ForeColor = Color.Black; lnk.Click += new EventHandler(this.lnk_Click); //lnk.ID = _reportDate;
} break; case "DDCCD": if (e.Row.Cells.FromKey("TrackingNumber").Value != null) { strTrackingNum = e.Row.Cells.FromKey("TrackingNumber").Value.ToString();
strTrackingNum = strTrackingNum.ToUpper();
if (strTrackingNum.StartsWith("1Z")) { //get the query string
s = "/Dctracking/upsActivity.aspx?Tracking_Number=" + e.Row.Cells.FromKey("TrackingNumber").Value.ToString(); //set the TargetURL //e.Row.Cells.FromKey("Tracking Number").TargetURL ="@" + s; e.Row.Cells.FromKey("TrackingNumber").TargetURL = s;
} } break;
default: //_tcId == null /* tc = (TemplatedColumn)e.Row.Cells.FromKey("DDC").Column; ci = (CellItem)tc.CellItems[e.Row.Index]; lnk = (LinkButton)ci.FindControl("LinkButton1"); if (lnk != null) { //int i = 0; lnk.Text = tblShipment.Rows[e.Row.Index][1].ToString(); lnk.ID = _arrLnkId[e.Row.Index]; //tc.Key; lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "','DDC');"; //lnk.Attributes.Add("onClick", "buttonClick('"tblShipment.Rows[e.Row.Index][1].ToString()"');"); //lnk.Attributes["onclick"] = "javascript:buttonClick('" + _oDr.GetString(i - 1).Trim() + "');"; lnk.Attributes["onmouseover"] = "this.style.color=\'#ff0000\'"; lnk.Attributes["onmouseout"] = "this.style.color=\'#000000\'"; lnk.ForeColor = Color.Black; lnk.Click += new EventHandler(this.lnk_Click); //lnk.ID = _reportDate;
}*/
break; }
if (_reportID == null) {
if (_bPClick == null) {
} //_bPClick.ToString(); /* TemplatedColumn tc = (TemplatedColumn)e.Row.Cells.FromKey("DDC").Column; CellItem ci = (CellItem)tc.CellItems[e.Row.Index]; LinkButton lnk = (LinkButton)ci.FindControl("LinkButton1"); if (lnk != null) { //int i = 0; lnk.Text = tblShipment.Rows[e.Row.Index][1].ToString(); lnk.ID = _arrLnkId[e.Row.Index];
lnk.Attributes["onclick"] = "javascript:buttonClick('" + lnk.Text + "');"; //lnk.Attributes.Add("onClick", "buttonClick('"tblShipment.Rows[e.Row.Index][1].ToString()"');"); //lnk.Attributes["onclick"] = "javascript:buttonClick('" + _oDr.GetString(i - 1).Trim() + "');"; lnk.Attributes["onmouseover"] = "this.style.color=\'#ff0000\'"; lnk.Attributes["onmouseout"] = "this.style.color=\'#000000\'"; lnk.ForeColor = Color.Black; lnk.Click += new EventHandler(this.lnk_Click); //lnk.ID = _reportDate;
} * / //lnk.Text = "test"; //lnk.Text = _reportDate; /* UltraWebGrid grid = sender as UltraWebGrid;
//2nd column TemplatedColumn tc = grid.Columns[0] as TemplatedColumn; CellItem item = tc.CellItems[e.Row.BandIndex] as CellItem; LinkButton linkbutton = item.FindControl("LinkButton1") as LinkButton;
if (linkbutton != null) {
e.Row.Cells[0].Value = _reportDate;
}*/ }
Please wait while we update your case...
North America sales@infragistics.com Sales: +1 (800) 231 8588 Fax: +1 (732) 831 7820
Europe sales-europe@infragistics.com Sales: +44 (0) 800 298 9055
Hello SunnyK,
Thank you for posting in our forums!
For the InitializeLayout event, what do you need to set using this event? It looks like you are mostly setting different styling in the code you provided. In the WebDataGrid, this is done through CSS. The rest of the properties can be accessed through the Column during Page_Load or some other event.
For the TemplatedColumnRestored event, since you are only setting the CellTemplate property in the UltraWebGrid, you can just set the Column's ItemTemplate property in any event for the WebDataGrid.
Our documentation has more information on using Item Templates for the columns.
And regarding the InitializeRow event, is there some specific issue you are running into while trying to access a control inside the template while using the WebDataGrid's InitializeRow event? Using FindControl will let you get access to a control inside the templates.
If you have any further questions or concerns with this, please let me know.
Mike,
I have the following code in InitializeRow for ultrawebgrid. How do I achieve the same in webdatagrid. I do not see CellItem in webdatagrid
UltraWebGrid grid = sender as UltraWebGrid;
TemplatedColumn tc;
CellItem ci;
LinkButton lnk;
//Switch on Templated column id
tc = (TemplatedColumn)e.Row.Cells.FromKey("DDC").Column;
ci = (CellItem)tc.CellItems[e.Row.Index];
lnk = (LinkButton)ci.FindControl("LinkButton1");
if (lnk != null)
//int i = 0;
lnk.Text = tblShipment.Rows[e.Row.Index][1].ToString();
lnk.ID = _arrLnkId[e.Row.Index];
lnk.Attributes["onclick"] = "BLOCKED SCRIPTbuttonClick('" + lnk.Text + "');";
lnk.Attributes["onmouseover"] = "this.style.color=\'#ff0000\'";
lnk.Attributes["onmouseout"] = "this.style.color=\'#000000\'";
lnk.ForeColor = Color.Black;
lnk.Click += new EventHandler(this.lnk_Click);
Tried the following code in webdatagrid
WebDataGrid grid = sender as WebDataGrid;
TemplateDataField tc = new TemplateDataField();
I need help with CellItem.
Thanks.
Michael,
In infragistics 2011 vol 1, I used the following code to switch on the templated column key
private class PlaceHolderTemplate : ITemplate
#region ITemplate Members
public void InstantiateIn(Control container)
CellItem ci = (CellItem)container;
switch(ci.Cell.Column.Key)
LinkButton lnk = new LinkButton();
lnk.ID = "LinkButton1";
lnk.Attributes.Add("onClick", "ClientClick();");
ci.Controls.Add(lnk);
I tried the following code in 2016 vol 2, but getting the error, I am not able to get reference to the template column key in grid. please help.
TemplateDataField tdf = new TemplateDataField();
switch (tdf.Key)
container.Controls.Add(lnk);
Thanks,
Srini
Hi Srini,
The TemplateContainer that is passed into the InstantiateIn method has an Item property that points to the cell the template is being applied to. You can use this to get the cell's column and the key.
Please see the code example for this below:
public void InstantiateIn(Control container){ TemplateContainer tmpl = container as TemplateContainer; GridRecordItem gridCell = tmpl.Item as GridRecordItem; switch (gridCell.Column.Key) ...
If you need anything else, please let me know.
Thank you Michael. Used your code as listed below.
Infragistics.Web.UI.TemplateContainer tmp1 = container as Infragistics.Web.UI.TemplateContainer;
GridRecordItem gri = tmp1.Item as GridRecordItem;
On different note:
I have a webdatagrid with unbound and templated columns, but data is not displaying for the unbound column. Do you have any sample code with webdatagrid using both unbound and templated columns?. Please see my code as listed below.
public void _fnRetrieveData(string _reportID,string _stNum)
switch(_reportID)
_oCmd = new SqlCommand("usp_rpt_Delivery_Count", _cn);
_oCmd.CommandType = CommandType.StoredProcedure;
_oParam = _oCmd.Parameters.Add("@store",SqlDbType.Int);
_oParam.Value = Convert.ToInt32(_storeNum);
_oParam = _oCmd.Parameters.Add("@fdate",SqlDbType.Char,10);
_oParam.Value = _stDate;
_oParam = _oCmd.Parameters.Add("@tdate",SqlDbType.Char,10);
_oParam.Value = _enDate;
tblShipment = new DataTable("Shipment");
tblShipment.Columns.Add(new DataColumn("Day", typeof(string)));
tblShipment.Columns.Add(new DataColumn("Expected In Store", typeof(string)));
//Add the grid columns manually
UnboundField col = new UnboundField();
col.Key = "Day";
col.Header.Text = "Day";
col.Width = Unit.Pixel(50);
this.wbgdata1.Columns.Add(col);
TemplateDataField tc = wbgdata1.Columns["DDC"] as TemplateDataField;
if (tc == null)
tc = new TemplateDataField();
tc.Key = "DDC";
tc.Header.Text = "Expected In Store";
tc.ItemTemplate = new PlaceHolderTemplate();
tc.Width = Unit.Pixel(60);
this.wbgdata1.Columns.Add(tc);
_cn.Open();
_oDr = _oCmd.ExecuteReader();
_retValue = false;
int _numrows = 0;
while(_oDr.Read())
DataRow r = tblShipment.NewRow();
r["Day"] = _oDr["Day"].ToString().Trim();
r["Expected In Store"] = _oDr["InStoreDate"];
tblShipment.Rows.Add(r);
wbgdata1.DataSource = tblShipment;
wbgdata1.DataBind();
wbgdata1.InitializeRow += wbgData1_InitializeRow;
--------------------------------------------------------------------------------------------------------------
protected void wbgData1_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e)
lnk = (LinkButton)e.Row.Items.FindItemByKey("DDC").FindControl("LinkButton1");
--------------------------------------------------------------------------------------------------------
GridRecordItem gri = (GridRecordItem)((Infragistics.Web.UI.TemplateContainer)(container)).Item;
switch (gri.Column.Key)
I saw you created a new support case (CAS-182991-J1B3X2) for this issue and it is currently being handled by Mike P.
If you have a new, specific issue, you should create a new support case or forum thread for it. Creating a new case/thread for each individual issue helps better organize responses and information related to them for review in the future.
If you need further assistance getting the templated cell's column key, please let me know.
Hi Mike,
I am able to get the templated cell's column key using your code. I will create a new support forum for future issues.