2011-12-13 4 views
1

코드 뒤에 설정하려고하는 표가 있습니다. 지금까지 모든 것이 순조롭게 진행되어 왔지만, 내가 itemcommand 이벤트 나 이벤트를 설정하려고 할 때 명령을 클릭하거나 이벤트를 트리거해야하는 작업을 수행 할 때 아무 것도 실행되지 않습니다. . 그래서 나는 정확히 내 아이템 명령에 대한 나의 선언을 잘못하고 있는지 궁금해하고 있었다. 당신은 아래에있는 내 코드를 찾을 수 있습니다 :프로그래밍 방식으로 itemcommand 이벤트를 설정

private void createRadGrid() 
    { 
     //create radgrid 
     RadGrid rg = new RadGrid(); 
     rg.ID = "RadGridView"; 

     //setting the datasource and itemcommand event handler. 
     rg.DataSourceID = "MachineDataSet"; 
     rg.ItemCommand += new GridCommandEventHandler(RadGridView_ItemCommand); 

     rg.Width = 862; 
     rg.CellSpacing = 2; 
     rg.CellPadding = 4; 
     rg.BorderWidth = 3; 
     rg.BackColor = System.Drawing.Color.Transparent; 
     rg.BorderColor = System.Drawing.Color.DarkGray; 
     rg.ForeColor = System.Drawing.Color.Black; 
     rg.ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
     rg.HeaderStyle.HorizontalAlign = HorizontalAlign.Center; 
     rg.BorderStyle = BorderStyle.Ridge; 
     rg.ShowStatusBar = true; 

     rg.AllowPaging = true; 
     rg.PageSize = 5; 
     rg.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric; 
     rg.AutoGenerateColumns = false; 

     rg.MasterTableView.PageSize = 5; 
     rg.MasterTableView.DataKeyNames = new string[] { "ID" }; 
     rg.MasterTableView.ClientDataKeyNames = new string[] { "ID" }; 
     rg.MasterTableView.AutoGenerateColumns = false; 

     rg.ClientSettings.Resizing.AllowColumnResize = true; 
     rg.ClientSettings.Resizing.EnableRealTimeResize = true; 
     rg.ClientSettings.Resizing.ResizeGridOnColumnResize = true; 

     GridBoundColumn boundColumn = new GridBoundColumn(); 
     boundColumn.DataField = "ID"; 
     boundColumn.HeaderText = "ID"; 
     boundColumn.UniqueName = "MachineID"; 
     boundColumn.Visible = false; 
     rg.MasterTableView.Columns.Add(boundColumn); 

     GridBoundColumn boundColumn1 = new GridBoundColumn(); 
     boundColumn1.DataField = "SiteName"; 
     boundColumn1.HeaderText ="Site Name"; 
     boundColumn1.Resizable = true; 
     boundColumn1.ReadOnly = true; 
     rg.MasterTableView.Columns.Add(boundColumn1); 

     GridBoundColumn boundColumn2 = new GridBoundColumn(); 
     boundColumn2.DataField = "Name"; 
     boundColumn2.HeaderText = "Machine Name"; 
     boundColumn2.Resizable = true; 
     boundColumn2.ReadOnly = true; 
     rg.MasterTableView.Columns.Add(boundColumn2); 

     GridBoundColumn boundColumn3 = new GridBoundColumn(); 
     boundColumn3.DataField = "MachineType"; 
     boundColumn3.HeaderText = "Machine Type"; 
     boundColumn3.Resizable = true; 
     boundColumn3.ReadOnly = true; 
     rg.MasterTableView.Columns.Add(boundColumn3); 

     GridBoundColumn boundColumn4 = new GridBoundColumn(); 
     boundColumn4.DataField = "MachineModel"; 
     boundColumn4.HeaderText = "Machine Model"; 
     boundColumn4.Resizable = true; 
     boundColumn4.ReadOnly = true; 
     rg.MasterTableView.Columns.Add(boundColumn4); 

     GridButtonColumn buttonColumn = new GridButtonColumn(); 
     buttonColumn.ButtonType = GridButtonColumnType.PushButton; 
     buttonColumn.CommandName = "AssignNewValues"; 
     buttonColumn.Resizable = true; 
     buttonColumn.Text = "Assign New Values"; 
     rg.MasterTableView.Columns.Add(buttonColumn); 

     PlaceHolder_RadGridView.Controls.Add(rg); 
    } 

문제 영역이 줄

rg.ItemCommand += new GridCommandEventHandler(RadGridView_ItemCommand); 

어떤 도움이나 제안이 크게 감사하는 것 같다. 이 줄을 이동

답변

2

보십시오. 그 사건 이후에 사건을 설정한다면, 그 사건의 이유가 될 수 없습니다.

희망 사항입니다.

건배.

+0

트릭을 잘못 찍었습니다. – James213

+0

동적 컨트롤로 작업 할 때 아주 흔히 볼 수있는 기사 인 http://msdn.microsoft.com/en-us/library/ms178472.aspx는 많은 도움을주었습니다. 페이지 수명주기의 어떤 부분에서해야 할 일. 건배 –

0

시도 :

PlaceHolder_RadGridView.Controls.Add(rg); 

오른쪽이 라인 이후에 :

RadGrid rg = new RadGrid(); 
rg.ID = "RadGridView"; 

그리고 그 차이를 만드는 경우를 참조하십시오. 어느 후 Page_Init 또는 를 Page_Load 이벤트에 createRadGrid()을 배치

+0

그래,이 시도하고 아무 것도 변경/일어난, 응답 주셔서 감사합니다 – James213

+0

좋아, 어디 createRadGrid() 다음 전화? 어떤 경우에? PreInit 또는 Init이어야합니다. –

+0

(! Page.IsPostBack) Page_load() 이벤트에서 실행하고 있었지만 지금은이 문장 밖에서 시도하고 있습니다. – James213

관련 문제