Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

i have image(print button) in gridview. i want to find gridview rowindex of imagebutton to print SSRS report

if any one knows pls help. i strucked in between the project.
Posted
Comments
[no name] 24-Sep-14 1:06am    
show your gridview code
Lokeshlnt 24-Sep-14 1:23am    
<asp:GridView ID="grdViewmyrequest" runat="server" SkinID="ItemGrid" AutoGenerateColumns="False" EmptyDataText="No Record Found" Width="100%" DataKeyNames="MaterialReq_ID">
<columns><asp:TemplateField>
<itemtemplate>
<asp:ImageButton ID="imgbtnprint" runat="server" ToolTip="Print" ImageUrl="~/Images/printer-icon_2.jpg"
Visible='<%# if(Eval("Workflow_Name")="CIO_Approved",True,False) %>' />


Lokeshlnt 24-Sep-14 1:26am    
<asp:GridView ID="grdViewmyrequest" runat="server" SkinID="ItemGrid" AutoGenerateColumns="False"
EmptyDataText="No Record Found" Width="100%" DataKeyNames="MaterialReq_ID">
<columns>
<asp:TemplateField>
<itemtemplate>
<asp:ImageButton ID="imgbtnprint" runat="server" ToolTip="Print" ImageUrl="~/Images/printer-icon_2.jpg"
Visible='<%# if(Eval("Workflow_Name")="CIO_Approved",True,False) %>' />


[no name] 24-Sep-14 6:29am    
if you are getting rowIndex then direct find
ImageButton btn=(ImageButton)grdViewmyrequest.Row[rowIndex].FindControl("imgbtnprint");

1 solution

Add an ImageButton to the GridView like:
XML
<ItemTemplate>
      <asp:ImageButton runat="server" ID="imageButton" ImageUrl='<%# Eval("objimg") %>'  CommandName="image" CommandArgument='<%# Eval("id") %>' OnClick="imageButtonCilck" />
      </ItemTemplate>

Define the event handler imageButtonCilck in Code-Behind:
protected void imageButtonCilck(object sender, EventArgs e)
    {
        //select the row
        ImageButton imageButton = (ImageButton)sender;
        TableCell tableCell = (TableCell)imageButton.Parent;
        GridViewRow row = (GridViewRow)tableCell.Parent;
        GridView1.SelectedIndex = row.RowIndex;
        
        //do your next step
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900