Hi ,
I am using Infragistics version 8.2
I want to add javascript function to onclick of a link button which is a templated column at 4th band
i need to pass some parameters(information related to that row) to javascript function.
Currently i am using Initialize row event but it is not working properly
Please suggest me how to achieve this.
Regards
Siva Prasad
Siva/Vince,
I am trying to add a templated link button to the second column of the bound webgrid at run time, but it always getting added to the first column. I have the following code.
DataTable
tblShipment = new DataTable("Shipment");
tblShipment.Columns.Add(
new DataColumn("Day", typeof(string)));
//Add templated cloumn
tc.Key =
"Templated";
tc.Header.Caption =
"Date";
tc.CellTemplate =
new PlaceHolderTemplate();
new DataColumn("Total Cartons", typeof(string)));
new DataColumn("Total Weight", typeof(string)));
private
class PlaceHolderTemplate : ITemplate
{
#region
ITemplate Members
public void InstantiateIn(Control container)
CellItem ci = (CellItem)container;
if (ci.Cell.Column.Key == "Templated")
LinkButton lnk = new LinkButton();
lnk.ID =
"LinkButton1";
lnk.Attributes.Add(
"onClick", "ClientClick();");
ci.Controls.Add(lnk);
}
protected
void wbgData_InitializeRow(object sender, RowEventArgs e)
lnk.Text =
"test";
How do I assign a value from datareader to templated link button.
Appreciate your help.
Thanks.
Hi Vince,
I changed my code based on your suggestion.
Now it is working fine.
Tnak you very much for your support
Siva,
A row's Index property reflects its position in the Rows collection that contains it. Each data island (a set of rows with the same parent row) has its own Rows collection. Because of this, the first row in each data island has an index of 0. So, given what code you've written, the result is correct.
Instead, I recommend that you use the row's BandIndex property instead. This property reflects the row's position with respect to all other rows in the same band, regardless of which parent row to which they belong. So, your code to get your "item" variable would be updated to:
CellItem item = ((CellItem)((TemplatedColumn)e.Row.Cells[4].Column).CellItems[e.Row.BandIndex]);
Hi,
The problem is when getting CellItem I made a mistake in InitializeRowEvent
CellItem
item = ((CellItem)((TemplatedColumn)e.Row.Cells[4].Column).CellItems[e.Row.Index]);
LinkButton lnk = item.FindControl("lnk") as LinkButton ;
For example grid is binded like this
First Band
SecondBand
Third Band
Fourth Band --- In this band i had Templated column and i need to attach Javascript function for the link button which is in this templated column.
In order to get cellitem i am using above logic
Javascript function is attaching but the problem is grid is binding like this.
Parent1
Child11
Child111
Child1111 --- RowIndex - 0
Child1112 --- RowIndex - 1
Child1113 --- RowIndex - 2
Parent2
Child22
Child222
Child2221 --- Again Row Index is initializing to 0, so same cellitem it is referrencing
Child2222
Child2223
Please correct me where i made mistake?
What do you mean by "not working properly"? Using InitializeRow to modify the CellItem corresponding to the cell for each row in your templated column is the best approach.