This is a migrated thread and some comments may be shown as answers.

Open Child Window from dynamically created LinkButton Attributes

0 Answers 47 Views
Window
This is a migrated thread and some comments may be shown as answers.
Katie
Top achievements
Rank 1
Katie asked on 28 Aug 2015, 11:51 AM

Hi

Please bear with me I'm quite new to Teleik. My scenario is I have a RadGrid which is built completely in C# code because the columns can vary. Each data bound field is either a link button or a label. For the link button I want to be able to open a child window which contains a RadGrid displaying the drill down data of the selected link button.

This is the code which builds the main RadGrid:

001.private Control DefineGridStructure(DataTable InGrid)
002.    {
003.        RadGrid grid = new RadGrid();
004.        grid.ID = "RadGridDetail";
005.        grid.DataSource = InGrid;
006.        grid.Skin = "Outlook";
007.        grid.Width = Unit.Percentage(100);
008.        grid.AllowPaging = false;
009.        grid.AutoGenerateColumns = false;
010.        grid.MasterTableView.Width = Unit.Percentage(100);
011.        grid.HeaderStyle.Font.Size = 10;
012.        grid.HeaderStyle.Font.Bold = true;
013.        grid.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
014. 
015.        try
016.        {
017.            grid.MasterTableView.DataKeyNames = new string[] { InGrid.Columns[1].ColumnName };
018. 
019. 
020.            GridBoundColumn Col1 = new GridBoundColumn();
021.            Col1.DataField = InGrid.Columns[0].ColumnName;
022.            //GridBoundColumn Col2 = new GridBoundColumn();
023.            //Col2.DataField = InGrid.Columns[1].ColumnName;
024. 
025.            if (InGrid.Columns[0].ColumnName == "PDESC")
026.            {
027.                Col1.HeaderText = "Problem Description";
028.                //Col2.HeaderText = "Problem Code";
029.            }
030.            else
031.            {
032.                Col1.HeaderText = "Region";
033.            }
034.            grid.Columns.Add(Col1);
035. 
036.            //Col3 - Query
037.            GridTemplateColumn Col3 = new GridTemplateColumn();
038.            Col3.ItemTemplate = new MyTemplate("Query", "£'s Val", "In Qry");
039.            Col3.HeaderText = "Query";
040.            grid.Columns.Add(Col3);
041. 
042.            //Col4 - 90D
043.            GridTemplateColumn Col4 = new GridTemplateColumn();
044.            Col4.ItemTemplate = new MyTemplate("D90", 4, "lnk");
045.            Col4.HeaderText = "90+ Days";
046.            grid.Columns.Add(Col4);
047. 
048.            //Col5 - Month 3
049.            GridTemplateColumn Col5 = new GridTemplateColumn();
050.            Col5.ItemTemplate = new MyTemplate("M3", 5, "lnk");
051.            Col5.HeaderText = Utils.GetMonth(3) + "-" + Utils.GetYear(3);
052.            grid.Columns.Add(Col5);
053. 
054.            //Col6 - Month 2
055.            GridTemplateColumn Col6 = new GridTemplateColumn();
056.            Col6.ItemTemplate = new MyTemplate("M2", 6, "lnk");
057.            Col6.HeaderText = Utils.GetMonth(2) + "-" + Utils.GetYear(2);
058.            grid.Columns.Add(Col6);
059. 
060.            //Col7 - Month 1
061.            GridTemplateColumn Col7 = new GridTemplateColumn();
062.            Col7.ItemTemplate = new MyTemplate("M1", 7, "lnk");
063.            Col7.HeaderText = Utils.GetMonth(1) + "-" + Utils.GetYear(1);
064.            grid.Columns.Add(Col7);
065. 
066.            //*****Building dynamic number of weeks column******
067.            DataTable NumWeeks = Utils.GetDataTable("SELECT * FROM [dbo].[fn_GetNumWeeks]() ORDER BY intWEEK ASC");
068.            int numOfWeeks = NumWeeks.Rows.Count;
069. 
070.            for (int i = 1; i < (numOfWeeks + 1); i++)
071.            {
072.                int columnNo = 7 + i;
073.                GridTemplateColumn Cols = new GridTemplateColumn();
074.                Cols.ItemTemplate = new MyTemplate("Wk" + i, columnNo, "lnk");
075.                Cols.HeaderText = Utils.GetMonth(0) + "<br/> " + "Week " + i;
076.                grid.Columns.Add(Cols);
077.            }
078.            //*************************************************
079. 
080.            //Col13 - MTD
081.            GridTemplateColumn Col13 = new GridTemplateColumn();
082.            Col13.ItemTemplate = new MyTemplate("MTD", 13, "lnk");
083.            Col13.HeaderText = "MTD";
084.            grid.Columns.Add(Col13);
085. 
086.            //Col14 - YTD
087.            GridTemplateColumn Col14 = new GridTemplateColumn();
088.            Col14.ItemTemplate = new MyTemplate("YTD", 14, "lbl");
089.            Col14.HeaderText = "YTD";
090.            grid.Columns.Add(Col14);
091. 
092.            //Col15 - OO/S
093.            GridTemplateColumn Col15 = new GridTemplateColumn();
094.            Col15.ItemTemplate = new MyTemplate("OOS", 15, "lbl");
095.            Col15.HeaderText = "Overall <br/> Outstanding";
096.            grid.Columns.Add(Col15);
097. 
098.            //Col16 - % OS Vs OV
099.            GridTemplateColumn Col16 = new GridTemplateColumn();
100.            Col16.ItemTemplate = new MyTemplate("Pct", 16, "lbl");
101.            Col16.HeaderText = "% Of Outstanding <br/> Vs Overall";
102.            grid.Columns.Add(Col16);
103. 
104.            ShowResult.Controls.Add(grid);
105.        }
106.        catch
107.        {
108.            //No records found.
109.        }
110.        return grid;
111. 
112.    }

The columns are generated using Templates:

01.Label[] lblVal = new Label[17];
02.        Label[] lblQty = new Label[17];
03. 
04.        LinkButton[] lnkVal = new LinkButton[17];
05.        LinkButton[] lnkQty = new LinkButton[17];
06. 
07.        public MyTemplate(string cName, int typeID, string clinkOrLabel)
08.        {
09.            ID = typeID;
10.            templateType = cName;
11.            colname = cName;
12.            linkOrLabel = clinkOrLabel;
13.            Params = 3;
14.        }

 And finally, this is the InstantiateIn code which creates the grid and prints it to the screen:

01.public void InstantiateIn(Control container)
02.        {
03.            Literal lc = new Literal();
04.            lc.Text = "<hr style='border: 1px;border-style: dotted;'/>";    
05. 
06.            if(templateType == "Query")
07.            {
08.                Label lblValQ = new Label();
09.                lblValQ.ID = colname + "Val";
10.                Label lblQtyQ = new Label();
11.                lblQtyQ.ID = colname + "Qty";
12.                lblValQ.Font.Size = 9;
13.                lblQtyQ.Font.Size = 9;
14.                 
15.                if (Params == 3)
16.                {
17.                    lblValQ.Text = ValCnt;
18.                    lblQtyQ.Text = QtyCnt;
19.                }
20.                container.Controls.Add(lblValQ);
21.                container.Controls.Add(lc);
22.                container.Controls.Add(lblQtyQ);
23.            }
24.            else
25.            {
26.                //decided whether the field should be a link button or a label
27.                if (linkOrLabel == "lnk")
28.                {
29.                    lnkVal[ID] = new LinkButton();
30.                    lnkVal[ID].DataBinding += lnkVal_DataBinding;
31.                    lnkVal[ID].Attributes.Add("OpenWindow", "openChildWindow(4,31,99);");
32.                    lnkQty[ID] = new LinkButton();
33.                    lnkQty[ID].DataBinding += lnkQty_DataBinding;
34.                    lnkQty[ID].Attributes.Add("OpenWindow", "openChildWindow(4, 31,99);");
35.                         
36.                    container.Controls.Add(lnkVal[ID]);
37.                    container.Controls.Add(lc);
38.                    container.Controls.Add(lnkQty[ID]);
39.                }
40.                else
41.                {
42.                    lblVal[ID] = new Label();
43.                    lblVal[ID].DataBinding += lblVal_DataBinding;
44.                    lblQty[ID] = new Label();
45.                    lblQty[ID].DataBinding += lblQty_DataBinding;                 
46. 
47.                    container.Controls.Add(lblVal[ID]);
48.                    container.Controls.Add(lc);
49.                    container.Controls.Add(lblQty[ID]);
50.                }
51.            }
52.        }

I am attempting to add Attributes to all the linkbuttons which will send to the javascript displayed below to get the data for the new window.   

1.<script type="text/javascript" language="javascript">
2.        function openChildWindow(Period, SalesMn, intWeek, ReasCode) {
3.            window.open('RadGridExportWebForm.aspx?Period=' + Period + '&SalesMn=' + escape(SalesMn) + '&intWeek=' + intWeek + '&ReasCode=' + ReasCode, 'childWindow', 'width=800,height=600,scrollbars=1,menubar=0,status=0,toolbar=0,resizable=1,titlebar=0', false);
4.        };
5.  </script>

However what is actually happening is the current page is simply reloading, it's not creating or opening a new window as I want it to.

I hope this makes sense

Any help would be greatly appreciated.

Many thanks!

No answers yet. Maybe you can help?

Tags
Window
Asked by
Katie
Top achievements
Rank 1
Share this question
or