Bind File Name from File Path in RadGrid

3 posts, 0 answers
  1. Chamara
    Chamara avatar
    40 posts
    Member since:
    Jun 2011

    Posted 30 Apr 2012 Link to this post

    i'm using following code to bind to RadGrid

    boundColumn = new GridBoundColumn();
                boundColumn.DataField = "ElectronicLocation";
                boundColumn.HeaderText = "Electronic Location";
                boundColumn.UniqueName = "ElectronicLocation";
                boundColumn.HeaderStyle.Width = Unit.Pixel(220);
                boundColumn.ItemStyle.BackColor = System.Drawing.Color.AliceBlue;
                RadGrid1.MasterTableView.Columns.Add(boundColumn);

    "ElectronicLocation" binds a file path which retrieved from sql query (ex:E:/Docs/aa.pdf).i need to display only the file name on the grid.is there any option available for this? 
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 30 Apr 2012 Link to this post

    Hello,

    Your above code is perfect.
    You have to add below logic in your code.

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem item = e.Item as GridDataItem;
     
                    string ste1 = item["ElectronicLocation"].Text;
                    if (ste1.LastIndexOf("/") > 0)
                    {
                        item["ElectronicLocation"].Text = ste1.Substring(ste1.LastIndexOf("/") + 1);
                    }
    }
    }


    Thanks,
    Jayesh Goyani
  3. Chamara
    Chamara avatar
    40 posts
    Member since:
    Jun 2011

    Posted 30 Apr 2012 Link to this post

    thank u for the reply.got it working..

    void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {


            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
               
                item["ElectronicLocation"].Text = Path.GetFileName(item["ElectronicLocation"].Text);
            }


        }
Back to Top