Hi allI have a WebDataGrid, I fill it in .aspx.ch like ".DataSource = SomeDataTable".The last column is empty and I like to have a button there on each row.OnClick I need to read some informations about the current row.I guess this should be done with TemplateDataField.How can I do this in the code behind after setting the DataSource ?Thanks and best regardsFrank Uray
Hi NikiforThanks, I see now what you mean :-)There is only one question left:How can I have the OnClick Event (Button1_Click) in C# ?I have tried the following, but it does not work.In the button click, I need to access the current row ...Thanks and best regardsFrank
private void return_Button_Cancel_Click(object sender, EventArgs e) { }
System.Web.UI.WebControls.Button _Button_Cancel = new System.Web.UI.WebControls.Button(); _Button_Cancel.Height = 25; _Button_Cancel.Width = 60; _Button_Cancel.Text = "Cancel"; _Button_Cancel.OnClientClick = "return_Button_Cancel_Click()"; container.Controls.Add(_Button_Cancel);
Hello Frank,Please take a look at the sample I attached. You have to add the template column in the templates collection of the grid in page Init event. Also the template is added for every row in initializeRow event not in the columns of the grid.
Hi NikiforI am using: "Infragistics4.Web.v11.2, Version=11.2.20112.2025".I did not paste the code in your sample, I am basicly doing the same.Following I send you my code.Thanks and best regardsFrank Uray
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace rch.zb.rms.web._standard { public partial class JobControl_Sessions : System.Web.UI.Page { private _classes.clsVariables _clsVariables = new _classes.clsVariables(); protected void Page_Load(object sender, EventArgs e) { try { this.Title = _classes.clsVariables.static_Title; if (!Page.IsPostBack) { // Check Request.QueryString if (Request.QueryString.Count == 0) { System.Web.HttpContext _HttpContext = System.Web.HttpContext.Current; _HttpContext.Items.Add(_classes.clsVariables.static_ErrorMessageKey, "No menu was selected ..."); _HttpContext.Items.Add(_classes.clsVariables.static_ErrorDescriptionKey, ""); Server.Transfer("../Error.aspx", false); return; } // End: if // Initialize _clsVariables.Initialize(); // Variables symmetric.processing.foundation._parameter.clsParameter _clsParameter = new symmetric.processing.foundation._parameter.clsParameter(); symmetric.processing.foundation._dynamic.clsDynamic _clsDynamic = new symmetric.processing.foundation._dynamic.clsDynamic(); int _MenuItemID = System.Convert.ToInt32(Request.QueryString["MenuItemID"].ToString()); string _Query = ""; this.WebDataGrid_JobControl_Sessions.InitializeRow -= new Infragistics.Web.UI.GridControls.InitializeRowEventHandler(WebDataGrid_JobControl_Sessions_InitializeRow); this.WebDataGrid_JobControl_Sessions.InitializeRow += new Infragistics.Web.UI.GridControls.InitializeRowEventHandler(WebDataGrid_JobControl_Sessions_InitializeRow); // Get Parameter System.Data.DataTable _DataTable_Parameters = _clsParameter.GetParameters(ref ((_classes.clsVariables)Session["clsVariables"]).public_clsSQLServer, _MenuItemID); System.Data.DataView _DataView_Parameters = new System.Data.DataView(_DataTable_Parameters); // Title _DataView_Parameters.RowFilter = "Name = 'Title'"; if (_DataView_Parameters.Count == 1) { this.Title = _DataView_Parameters[0]["Value"].ToString(); } _Query = "SELECT [Fld_PK] AS [ID], "; _Query += " [Fld_FK_Jobs] AS [FK_Jobs], "; _Query += " (SELECT [Fld_JobName] "; _Query += " FROM [_JOBCONTROL].[dbo].[Tbl_Jobs] "; _Query += " WHERE [Fld_PK] = js.[Fld_FK_Jobs]) AS [JobName], "; _Query += " [Fld_RunningCounter] AS [RunningCounter], "; _Query += " [Fld_ThreadID] AS [ThreadID], "; _Query += " [Fld_Cancel] AS [Cancel], "; _Query += " null AS [Action] "; _Query += "FROM [_JOBCONTROL].[dbo].[Tbl_Jobs_Sessions] js"; this.WebDataGrid_JobControl_Sessions.DataSource = ((_classes.clsVariables)Session["clsVariables"]).public_clsSQLServer.GetDataTable(_Query); if (((System.Data.DataTable)this.WebDataGrid_JobControl_Sessions.DataSource).Rows.Count != 0) { this.WebDataGrid_JobControl_Sessions.DataBind(); } else { this.WebDataGrid_JobControl_Sessions.DataSource = null; } Infragistics.Web.UI.GridControls.TemplateDataField field1 = new Infragistics.Web.UI.GridControls.TemplateDataField(); field1.Key = "TemplateColumn1"; field1.Header.Text = "Edit"; this.WebDataGrid_JobControl_Sessions.Columns.Add(field1); } // End: if } // End: try catch (Exception ex) { System.Web.HttpContext _HttpContext = System.Web.HttpContext.Current; if (!_HttpContext.Items.Contains(_classes.clsVariables.static_ErrorMessageKey)) { _HttpContext.Items.Add(_classes.clsVariables.static_ErrorMessageKey, ex.Message); } else { _HttpContext.Items[_classes.clsVariables.static_ErrorMessageKey] = ex.Message; } if (!_HttpContext.Items.Contains(_classes.clsVariables.static_ErrorDescriptionKey)) { _HttpContext.Items.Add(_classes.clsVariables.static_ErrorDescriptionKey, ex.Message); } else { _HttpContext.Items[_classes.clsVariables.static_ErrorDescriptionKey] = ex.Message; } Server.Transfer("../Error.aspx", false); } // End: catch } private void WebDataGrid_JobControl_Sessions_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e) { e.Row.Items[0].Column.Hidden = true; e.Row.Items[1].Column.Hidden = true; e.Row.Items[3].Column.Hidden = true; e.Row.Items[4].Column.Hidden = true; e.Row.Items[5].Column.Hidden = true; } } }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JobControl_Sessions.aspx.cs" Inherits="rch.zb.rms.web._standard.JobControl_Sessions" %> <%@ Register Assembly="Infragistics4.Web.v11.2, Version=11.2.20112.2025, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.Web.UI" TagPrefix="ig" %> <%@ Register Assembly="Infragistics4.Web.v11.2, Version=11.2.20112.2025, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <meta http-equiv="refresh" content="5"/> </head> <body> <form id="form1" runat="server"> <div> <ig:WebScriptManager ID="WebScriptManager_JobControl_Sessions" runat="server"></ig:WebScriptManager> <ig:WebDataGrid ID="WebDataGrid_JobControl_Sessions" runat="server" Height="100%" Width="100%" StyleSetName="Windows7" AutoGenerateColumns="True"> <ig:Columns> <ig:TemplateDataField Key="Action"> <ItemTemplate> <asp:Button ID="TestButton" runat="server" Text="TestButton" /> </ItemTemplate> </ig:TemplateDataField> </ig:Columns> </ig:WebDataGrid> </div> </form> </body> </html>
Hello Frank, Can you please provide some basic information about what is your exact build of NetAdvantage, does the issue reproduce in all the browsers you have used to test and what are they. Also are you putting the code you have pasted in the same events as in the attached from me sample.
Hi NikiforThanks for your answer.When set the datasource like this:this.WebDataGrid_JobControl_Sessions.DataSource = SomeTable;this.WebDataGrid_JobControl_Sessions.DataBind();I get the grid in the browser.When I add the following lines after this, there is no grid displayed any more: TemplateDataField field1 = new TemplateDataField(); field1.Key = "TemplateColumn1"; field1.Header.Text = "Edit"; this.WebDataGrid_JobControl_Sessions.Columns.Add(field1);
What am I doing wrong ??Thanks and best regardsFrank Uray