Hello,
Does anyone know how to associate a LinkButton (webform control) to a webgrid row data?
I have an ultrawebgrid with three columns, column ID, column Status, and column Command (Add). The Add command is a link button (web form control). Everytime I click on the Add link button, I need to retrieve the Column ID and Column Status and and pass it to a modal dialog to change the current status and update it into the database.
Thanks in advance for your help.
Hs2
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
Hi,
I am new to Infragistics controls.
I am using Ultrawebgrid control and tried to create a template field for a column in the grid, just like you mentioned using LinkButton control.
But, I am unable to set the Text attribute for it.
I want to set the grid cells text in the text attribute.
<igtbl:TemplatedColumn BaseColumnName="MakeModel" IsBound="true" Key="MakeModel" Width="200px" Type="Custom"> <Header Caption="SPC Model"> <RowLayoutColumnInfo OriginX="1" /> </Header> <CellTemplate> <asp:LinkButton ID="ID" Text="Press" OnClick="Link_Click" CommandName="Edit" CommandArgument="<%# Container.Cell.Row.Index %>" runat="server" /> </CellTemplate> <Footer> <RowLayoutColumnInfo OriginX="1" /> </Footer> </igtbl:TemplatedColumn>