Archive for the ‘Asp.Net 2.0’ Category

Urgent: How to associate LinkButton (webform control) to a webgrid row data asp.net 2.0 c#

February 8, 2008
First, you can create a TemplatedColumn to place the LinkButton control inside of the column:<igtbl:TemplatedColumn BaseColumnName=”ProductName” IsBound=”True” Key=”ProductName”>
<Header Caption=”ProductName”>
<RowLayoutColumnInfo OriginX=”1″ />
</Header>
<CellTemplate>
<asp:LinkButton runat=”server” ID=”MyLinkButton” Text=”Press Me” CommandName=”Edit” OnClick=”MyLinkButton_Click” CommandArgument=”<%# Container.Cell.Row.Index %>” />
</CellTemplate>
<Footer>
<RowLayoutColumnInfo OriginX=”1″ />
</Footer>
</igtbl:TemplatedColumn>
In the LinkButton in the template there are a couple things to notice.  First, the Click event is specified with a event handler MyLinkButton_Click method defined.  Next, the CommandArgument property is specified.  Its value is set to the Index of the Row that the Cell the LinkButton is in.

Then in your code behind, all you need to do is define the Click events handler then access the LinkButtons CommandArgument to figure out what row was clicked.  Once you know the row, you can get the values from any cell in that row:

protected void MyLinkButton_Click(object sender, EventArgs e)
{
    LinkButton button = (LinkButton)sender;
    System.Diagnostics.Debug.WriteLine(String.Format(“Button Clicked in row {0}”, button.CommandArgument.ToString()));

    object id = this.UltraWebGrid1.Rows[int.Parse(button.CommandArgument)].Cells.FromKey(“ColumnID”).Value;
    object status = this.UltraWebGrid1.Rows[int.Parse(button.CommandArgument)].Cells.FromKey(“ColumnStatus”).Value;
}

Hope that helps.

Devin

Product Manager :: Web Client
http://www.infragistics.comhttp://blogs.infragistics.com/blogs/devin_rader/
http://www.geekswithblogs.com/devin

Infragistics Developer Support: http://www.infragistics.com/gethelp