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.
Hi SunnyK,
I'm updating the thread based on the phone call we just had.
Here is the forum thread I found that discusses how you can access the templated cell of the row during the InitializeRow event.
https://www.infragistics.com/community/forums/f/ultimate-ui-for-asp-net/45205/find-control-in-a-templated-column
Then, based on the "DDC" case you have, you would want to use the following code instead:
[code]switch (_reportID){ case "DDC": //tc = (TemplatedColumn)e.Row.Cells.FromKey("DDC").Column; //ci = (CellItem)tc.CellItems[e.Row.Index]; lnk = (LinkButton)e.Row.Items["DDC"].FindControl("LinkButton1");
if (lnk != null) { //int i = 0; lnk.Text = tblShipment.Rows[e.Row.Index][1].ToString(); lnk.ID = _arrLnkId[e.Row.Index]; ...[/code]
Alternatively, after our call I realized that CellItem is equivalent to the GridRecordItem in the WebDataGrid. You don't need to store this in a variable like with the CellItem, but I thought it would be useful information for you.
e.g.
[code]GridRecordItem gri = e.Row.Items["DDC"];[/code]
If you have any further questions or concerns with this, please let me know and I will be glad to help.
I must be confusing some of our collections indexers. You called in again and another coworker spoke with you about this. He just brought this to my attention about how you are receiving an error trying to use e.Row.Items["DDC"].
After checking our documentation, the indexer for the Items collection only takes an integer, which is why you are getting the error. Instead, you could use the following code to get the cell by the column key:
lnk = (LinkButton)e.Row.Items.FindItemByKey("DDC").FindControl("LinkButton1");
I apologize for any confusion. If you need anything else, please let me know.
Michael,
In ultrawebgrid using page load event I am creating the grid columns and add templated columns as listed below. DDC is a key for the template column.
//Add the grid columns manually
UltraGridColumn col = new UltraGridColumn();
col.Key = "Day";
col.BaseColumnName = "Day";
col.Header.Caption = "Day";
col.Width = Unit.Pixel(50);
this.wbgData.Bands[0].Columns.Add(col);
//Add templated cloumn
TemplatedColumn tc = new TemplatedColumn(true);
tc.Key = "DDC";
tc.BaseColumnName = "Expected In Store";
tc.Header.Caption = "Expected In Store";
tc.CellTemplate = new PlaceHolderTemplate();
tc.Width = Unit.Pixel(50);
this.wbgData.Bands[0].Columns.Add(tc);
In Initializerow event, I switch on the template column id (DDC). DDC is not the key for LinkButton. I do not see any reference to template column in the code
Please help me with the code for finding linkbutton for template column key DDC.