This is a migrated thread and some comments may be shown as answers.

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

3 Answers 58 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tanu
Top achievements
Rank 1
Tanu asked on 23 Jan 2013, 02:33 PM
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

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Jan 2013, 06:19 AM
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
0
Tanu
Top achievements
Rank 1
answered on 24 Jan 2013, 07:05 AM
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
0
Princy
Top achievements
Rank 2
answered on 25 Jan 2013, 06:48 AM
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
Tags
General Discussions
Asked by
Tanu
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Tanu
Top achievements
Rank 1
Share this question
or