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

using image button in grid

1 Answer 160 Views
Grid
This is a migrated thread and some comments may be shown as answers.
heba
Top achievements
Rank 1
heba asked on 16 Feb 2014, 07:47 PM
I used image button in TemplateColumn I want to get DataKeyNames(id)  value of row when Image button clicked  to view PDF file that  stored in server and has the same name as id of row in new tab, how can I do this 
Thanks

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Feb 2014, 04:37 AM
Hi Heba,

Please take a look at the sample code snippet, you can try a similar approach.

C#:
//Image Button Click
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
  ImageButton img = (ImageButton)sender;
  GridDataItem item = (GridDataItem)img.NamingContainer;
  string id = item.GetDataKeyValue("ID").ToString();  // Access the selected row ID  
}
 
//To open a new Tab
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
    GridDataItem item = (GridDataItem)e.Item;
    ImageButton imgbtn = (ImageButton)item.FindControl("ImageButton1");       
    imgbtn.Attributes.Add("onclick", "document.forms[0].target= '_new';return true;"); // Open a newtab
  }
}

Thanks,
Princy
Tags
Grid
Asked by
heba
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or