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"] = "BLOCKED SCRIPTbuttonClick('" + lnk.Text + "');"; //lnk.Attributes["onclick"] = "BLOCKED SCRIPTbuttonClick('" + lnk.Text + "','DDC');"; //lnk.Attributes.Add("onClick", "buttonClick('"tblShipment.Rows[e.Row.Index][1].ToString()"');"); //lnk.Attributes["onclick"] = "BLOCKED SCRIPTbuttonClick('" + _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"] = "BLOCKED SCRIPTbuttonClick('" + lnk.Text + "');"; //lnk.Attributes["onclick"] = "BLOCKED SCRIPTbuttonClick('" + lnk.Text + "','DDC');"; //lnk.Attributes.Add("onClick", "buttonClick('"tblShipment.Rows[e.Row.Index][1].ToString()"');"); //lnk.Attributes["onclick"] = "BLOCKED SCRIPTbuttonClick('" + _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"] = "BLOCKED SCRIPTbuttonClick('" + lnk.Text + "');"; //lnk.Attributes["onclick"] = "BLOCKED SCRIPTbuttonClick('" + lnk.Text + "','DDC');"; //lnk.Attributes.Add("onClick", "buttonClick('"tblShipment.Rows[e.Row.Index][1].ToString()"');"); //lnk.Attributes["onclick"] = "BLOCKED SCRIPTbuttonClick('" + _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"] = "BLOCKED SCRIPTbuttonClick('" + lnk.Text + "');"; //lnk.Attributes["onclick"] = "BLOCKED SCRIPTbuttonClick('" + 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"] = "BLOCKED SCRIPTbuttonClick('" + lnk.Text + "');"; //lnk.Attributes["onclick"] = "BLOCKED SCRIPTbuttonClick('" + 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"] = "BLOCKED SCRIPTbuttonClick('" + lnk.Text + "');"; //lnk.Attributes["onclick"] = "BLOCKED SCRIPTbuttonClick('" + lnk.Text + "','DDCTLV');"; //lnk.Attributes.Add("onClick", "buttonClick('"tblShipment.Rows[e.Row.Index][1].ToString()"');"); //lnk.Attributes["onclick"] = "BLOCKED SCRIPTbuttonClick('" + _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"] = "BLOCKED SCRIPTbuttonClick('" + lnk.Text + "','DDC');"; //lnk.Attributes.Add("onClick", "buttonClick('"tblShipment.Rows[e.Row.Index][1].ToString()"');"); //lnk.Attributes["onclick"] = "BLOCKED SCRIPTbuttonClick('" + _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"] = "BLOCKED SCRIPTbuttonClick('" + lnk.Text + "');"; //lnk.Attributes.Add("onClick", "buttonClick('"tblShipment.Rows[e.Row.Index][1].ToString()"');"); //lnk.Attributes["onclick"] = "BLOCKED SCRIPTbuttonClick('" + _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;
}*/ }
Hello,
The best approach to take when migrating from the UltraWebGrid to the WebDataGrid is to start with the functionality you need from the new control and look at the best way to achieve that functionality with the newer control. Once you have that it is best to evaluate what existing code can be reused.
From the code provided it appears to be styling the grid and adding templated columns. For the styling, this should be done in CSS with the WebDataGrid and for the templates with link buttons, I would recommend reviewing what you need to accomplish when clicking the link and evaluating if there is a better alternative. For example you can use a html link with for navigation or you can use a html link that executes javascript if the functionality can be done on the client side. If you do need to use a template, then it would be best to review the Templates section of the help for the WebDataGrid.
Let me know if you have any questions with this matter.
Ok, thanks.