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
Hello Frank,Please take a look at the created from me sample with NetAdvantage 11.2.20112.2055. The grid implements the scenario form the following page of our online help - http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.2/CLR4.0/html/WebDataGrid_Using_Item_Template.html
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
Hello Frank,I have tested the sample again with IE 9, Chrome, FF 10 under Win 7 64 bit. All the browsers act the same. I am able to enter in the event when the button is pressed. The page makes postback and after this the grid is with the same data – no rows are cleared. Please confirm that you are facing the behavior in the sample. If so please confirm that your version is still 11.2.20112.2025 and you have not upgraded to a new one (I tested it with 11.2.20112.2086 too). Please in future do not paste your code but attach it in *.zip files to every forum post
Hello Frank,Please let me know if you have any further questions regarding this issue.
Hi NikiforSorry for the delayed answer.Attached I send you a sample solution.In the code behind, the button_click should be called whena button is clicked. I should also get the current row there.Thanks a lot for a quick answer.RegardsFrankby the way: 200kb for attachment is not very much :-)Had to delete ig_res
Hello Frank,
The event was not firing due to the way you are trying to set the template. I am attaching the modified sample with the event firing. It is not possible to have the row index in the click event which is defined in class in which this control is not defined. I have modified the InitializeRow event to keep the row index and when the ItemCommand you can get the index of the selected row. This is the reccomended approach for ASP.
Thanks for your answer.This only works because you are duplicating the columns ...When you do this, it does not work any more: if (!IsPostBack) { //BoundDataField bf = new BoundDataField(); //bf.Key = "Column01"; //bf.DataFieldName = "Column01"; //bf.Header.Text = "Column01"; //this.WebDataGrid_Test.Columns.Add(bf); //bf = new BoundDataField(); //bf.Key = "Column02"; //bf.DataFieldName = "Column02"; //bf.Header.Text = "Column02"; //this.WebDataGrid_Test.Columns.Add(bf); //TemplateDataField tf = new TemplateDataField(); //tf.Key = "Button"; //tf.Header.Text = "Button"; //this.WebDataGrid_Test.Columns.Add(tf); }
In my case, the data is coming from a database and I only knowI will have a empty column called "Action". There the button should be.All other columns are dynamicly and I dont know while design time.RegardsFrank
Please let me know if you have any further questions regarding this issue. Did you manage to resolve it?
Hello Frank,Did you have the chance to test my suggestion? When you have auto generated columns they are not available through grid.Columns - this collection is containing only the columns added through the mark up or added through the server side code. You are adding only the template column. The other 3 are auto generated. In initializeRow event you are available to manipulate the columns by getting them through the row items as shown. The first items are the added columns and they will be at the beginning of the collection. At the end of the collection are the 3 autogenerated columns. You can set the last column (3 )to be with visibility false and to set the first column which is your template column to be with last visible index like
e.Row.Items[3].Column.Hidden = true;
e.Row.Items[0].Column.VisibleIndex = 3;
The null exception was because you are looking for the button in the autogenerated column not in the template one.
Please let me know if this answer makes any sense.
Hi NikiforThanks for your answer.Well, I really dont unterstand this concept ???When I set VisibleIndex I get one column called Button without a buttonand another column also called Button with the button.All I need to do is:I am getting a datatable from the sql server.I set DataSource and DataBind of the grid.The last column of the datatable is always empty and thereI need to have a button.On button click, in the event (code behind)I need to identify the current row to get some values out of it.RegardsFrank Uray
Hello Frank,You are getting this exception because the btn is null. IT is null because the last column is not containing it. If what you are trying to achieve is to set the column with the button to be last shown you can set the visible index of the column like this:private void WebDataGrid_Test_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e)
{
e.Row.Items[0].Column.Hidden = false;
e.Row.Items[1].Column.Hidden = false;
// e.Row.Items[2].TemplateId = "ActionButtons";
e.Row.Items[2].Column.Width = 100;
e.Row.Items[3].Column.Hidden = false;
Button btn = (Button)e.Row.Items[0].FindControl("_Button_Cancel_ID");
btn.CommandArgument = e.Row.Index.ToString();
btn.CommandName = "Cancel";
}
Hi NikiforTry to put the button to the last column: e.Row.Items[3].Column.Hidden = false; Button btn = (Button)e.Row.Items[3].FindControl("_Button_Cancel_ID");
There will be an exception raised: "Object reference not set to an instance of an object."on the line:btn.CommandArgument = e.Row.Index.ToString();
Thanks and best regardsFrank Uray