I added a linkbutton in a TemplatedField in a WebGrid.When I Click the LinkButton,How To Get the Row index in LinkButton Click event??
Alternatively -
templated column markup:
<igtbl:TemplatedColumn> <CellTemplate> <asp:LinkButton runat="server" ID="lblName" Text='<%# Eval("BoundColumnName") %>' CommandName="YourCommandName" CommandArgument="<%# Container.Cell.Row.Index %>" OnCommand="OnButtonCommand" /> </CellTemplate> </igtbl:TemplatedColumn>
Code behind:
protected void OnButtonCommand(object sender, CommandEventArgs e) { LinkButton btn = (LinkButton)sender; int rowIndex = int.Parse(btn.CommandArgument); }
Hello Guys,
@Emil - thanks for sharing your approach in forums, that sounds like a great idea. In any case, much better than the best I could come up with:
<igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" Height="200px" Width="325px" DataSourceID="AccessDataSource1" > <Bands> <igtbl:UltraGridBand> <Columns> <igtbl:TemplatedColumn> <CellTemplate> <asp:DropDownList runat="server" ID="DropDownList1" OnInit="DropDownList1_OnInit"> </asp:DropDownList> </CellTemplate> </igtbl:TemplatedColumn> </Columns> </igtbl:UltraGridBand> </Bands> ...</igtbl:UltraWebGrid> protected void DropDownList1_OnInit(object sender, EventArgs e) { DropDownList dropDownList = sender as DropDownList; CellItem parentCell = (CellItem) dropDownList.NamingContainer;
int rowIndex =parentCell.Cell.Row.BandIndex;
}