Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
769
Urgent: How to associate LinkButton (webform control) to a webgrid row data asp.net 2.0 c#
posted

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

 

Parents
  • 12631
    posted

    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

Reply Children