To click a button out of n number of buttons with same name

4 posts, 0 answers
  1. Tanu
    Tanu avatar
    2 posts
    Member since:
    Jan 2013

    Posted 23 Jan 2013 Link to this post

    My application contains a datagrid. Each record have different values but buttons(Edit button) with same name against each record. how to click a particular button corresponding to a particular record using test studio
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Jan 2013 Link to this post

    Hi,

    I suppose you want to attach a Click event for the Edit button in RadGrid. Here is the sample code.
    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               GridDataItem dataItem = (GridDataItem)e.Item;
               LinkButton link = (LinkButton)dataItem["edit"].Controls[0];
               link.Click += new EventHandler(link_Click);
           }
       }
     void link_Click(object sender, EventArgs e)
       {
       }

    Thanks,
    Princy
  3. Tanu
    Tanu avatar
    2 posts
    Member since:
    Jan 2013

    Posted 24 Jan 2013 Link to this post

    Hi Princy,

    Thanks for the reply. The grid is not a radgrid. It is asp gridview, default grid with asp.net. Though major of the grids used in my application is radgrid but this not the one. So can you help now?
    And scenario is like
    Name Opeartion
    ABC Edit Role Delete
    DEF Edit Role Delete
    GHI Edit Role Delete
    JKL Edit Role Delete
    MNO Edit Role Delete etc......

    where you have to click on Edit Role corresponds to a Name like JKL., and the order is always dynamic
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Jan 2013 Link to this post

    Hi,

    Try the following code.
    C#:
    foreach (GridViewRow row in GridView1.Rows)
        {
            LinkButton lb = (LinkButton)row.Cells[0].Controls[0];
            lb.Click += new EventHandler(lb_Click);
        }
     void lb_Click(object sender, EventArgs e)
    {
     }

    Thanks,

    Princy
Back to Top