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

button in datagrid and selecting rows

1 Answer 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ehsan
Top achievements
Rank 1
ehsan asked on 10 Feb 2009, 05:28 AM
hi telerik
i have a button in my grid like this :
<telerik:GridTemplateColumn HeaderText="edit"
      <ItemTemplate> 
            <asp:Button ID="btn" runat="server" Text="edit" Font-Names="tahoma" OnClick="clk" /> 
      </ItemTemplate> 
 </telerik:GridTemplateColumn> 

i want when i click on my button in radgrid i know wich button in wich row item is clicked.
in other ways i want to get row index of clicked button and get record ID to another operations

i do  this in onClick event  in [clk] function:

 int es_ID = int.Parse(RadGrid1.MasterTableView.DataKeyValues[0]["es_ID"].ToString()); 
 
ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), "showdialog(1,1);"true); 
but in RadGrid1.MasterTableView.DataKeyValues[ ?] <<< i cant get  clicked row index

do you have idea about my problem?
tnx

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 10 Feb 2009, 06:15 AM
Hi Ehsan,

Try the below code snippets for getting the rowindex of clicked row and the value of corresponding row.

CS:
protected void btn_Click(object sender, EventArgs e) 
    Button editbutton = (Button)sender; 
    GridDataItem item = (GridDataItem)editbutton.NamingContainer;  //Row 
    int Index = item.ItemIndex; // index 
    string es_ID= item["es_ID"].Text; // clicked row value 

ASPX:
<telerik:GridTemplateColumn UniqueName="edit" HeaderText="edit"
<ItemTemplate> 
        <asp:Button ID="btn" runat="server" Text="edit" Font-Names="tahoma" onclick="btn_Click" /> 
</ItemTemplate> 
</telerik:GridTemplateColumn> 

Thanks,
Shinu.
Tags
Grid
Asked by
ehsan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or