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

HELP: Retrieve value from Radgrid Selected Row and pass the value to an asp.net image control to display the image.

1 Answer 20 Views
Grid
This is a migrated thread and some comments may be shown as answers.
huejiitech
Top achievements
Rank 1
huejiitech asked on 04 Aug 2013, 04:28 AM
 

Hi,

Need Help in Retrieving Image.
I have a Radgrid populated by a records of file name of image.

images are located in "~/images/"
ex.
----------------
filename
apple.jpg    
Cherry.jpg 
tuna.jpg      
dog.jpg
bottle.jpg
----------------

my Code to populated those filename:

        Dim filePaths() As String = Directory.GetFiles(Server.MapPath("~/images"))
        Dim files As List(Of ListItem) = New List(Of ListItem)
        For Each filePath As String In filePaths
            files.Add(New ListItem(Path.GetFileName(filePath), filePath))
        Next
        Radgri1.DataSource = files
        Radgri1
Radgri1.DataBind()


-----------------------------------------

all i want is When the user click a row in the Radgrid1 it will return the file name and will concatenate with file path location :

Ex.
dim strRowSelected = "Apple.jpg"

Image1.imageurl = "~/images" & strRowSelected

where the "Apple.jpg" is from the user selected row from the Radgrid1

and finally it will display the image to an asp.net image control.

How do i do that?

please help, and kindly refer the the attached file for the scenario










1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 05 Aug 2013, 06:46 AM
Hello,

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
       OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">
       <MasterTableView>
           <Columns>
               <telerik:GridBoundColumn DataField="Text" HeaderText="Text" UniqueName="Text">
               </telerik:GridBoundColumn>
           </Columns>
       </MasterTableView>
       <ClientSettings EnablePostBackOnRowClick="true">
           <Selecting AllowRowSelect="true" />
       </ClientSettings>
   </telerik:RadGrid>
   <asp:Image ID="Image1" runat="server" />
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
       string[] filePaths = Directory.GetFiles(Server.MapPath("~/images"));
       List<ListItem> ListItems = new List<ListItem>();
 
       foreach (string str in filePaths)
       {
           ListItems.Add(new ListItem(Path.GetFileName(str), str));
       }
 
       RadGrid1.DataSource = ListItems;
   }
   protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
   {
       if (RadGrid1.SelectedItems.Count > 0)
       {
           GridDataItem item = RadGrid1.SelectedItems[0] as GridDataItem;
           Image1.ImageUrl = Server.MapPath("~/images/" + item["Text"].Text);
       }
       else
       {
           Image1.ImageUrl = string.Empty;
       }
   }


If your grid ajaxify then

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
       <AjaxSettings>
           <telerik:AjaxSetting AjaxControlID="RadGrid1">
               <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                   <telerik:AjaxUpdatedControl ControlID="Image1" LoadingPanelID="RadAjaxLoadingPanel1" />
               </UpdatedControls>
           </telerik:AjaxSetting>
       </AjaxSettings>
   </telerik:RadAjaxManager>
   <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
   </telerik:RadAjaxLoadingPanel>


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
huejiitech
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or