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

Bind File Name from File Path in RadGrid

2 Answers 92 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chamara
Top achievements
Rank 1
Chamara asked on 30 Apr 2012, 04:21 PM
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 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Apr 2012, 05:59 PM
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
0
Chamara
Top achievements
Rank 1
answered on 01 May 2012, 02:37 AM
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);
        }


    }
Tags
General Discussions
Asked by
Chamara
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Chamara
Top achievements
Rank 1
Share this question
or