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

Out of Range Exception

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Animesh
Top achievements
Rank 1
Animesh asked on 22 Feb 2018, 06:20 PM

Hi I am new to programming. My requirement is limited. My radgrid is populated with data using stored procedure. Now when I wants to view the data I am getting out of range exception. The exception is thrown on SelectedIndexChanged event.The code is as follows:

 

Aspx:

Loading the radgrid
TGRCircularAIBOC.DataSource = Resources.GetCircular("AIBOC");
            TGRCircularAIBOC.DataBind();
<telerik:RadGrid ID="TGRCircularAIBOC" runat="server" Skin="Office2007" OnSelectedIndexChanged="TGRCir
protected void TGRCircularAIBOC_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridDataItem dataitem = (GridDataItem)TGRCircularAIBOC.SelectedItems[0];
        string CircularNo = dataitem["CircularNo"].ToString();
        string AuthorityCode = "AIBOC";
        byte[] BinaryPDF = Resources.ViewCircular(CircularNo, AuthorityCode);
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment; filename = " + "Circular");
        Response.BufferOutput = true;
        Response.BinaryWrite(BinaryPDF);
        Response.Flush();
        Response.End();
    }
Actually I am trying to display a pdf here which is fetched in varbinary format...
cularAIBOC_SelectedIndexChanged">  
                        <ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true" ></ClientSettings>
                    </telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 23 Feb 2018, 02:37 PM
Hi Animesh,

Have you had the chance to try out the suggested solution or test the sample I've attached in the other forum thread (SelectedIndexChanged event of RadGrid)?

Also, to get the cell value use the text property of the Cell. (Accessing Cells Using Column Unique Name)
string CircularNo = dataitem["CircularNo"].Text.ToString();

Additionally, you might use a condition that will count the selected items and only run the logic if there is at least one item in the collection.
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
    if(TGRCircularAIBOC.SelectedItems.Count > 0){
        GridDataItem dataitem = (GridDataItem)TGRCircularAIBOC.SelectedItems[0];
        // do something
    }
}

Give the suggestion above a try to see if that works for you.

Kind regards,
Attila Antal
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Animesh
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or