How to bind Gridview with sharepoint list column type hyperlink or picture

Hi Friends,

I have a sharepoint 2013 on premises custom list with column type hyperlink or picture and few more columns also.

I have to bind all columns to gridview(Visual webpart) and for this hyperlink or picture field i have to show only description instead of url.

public DataTable GetAll()
        {
            SPSite objSite = SPContext.Current.Site;

            using (SPWeb objWeb = objSite.OpenWeb())
            {

                SPQuery objQuery = new SPQuery();
                
                objQuery.ViewFields = "<FieldRef Name='Title'/>" + "<FieldRef Name='JobNumber'/>" + "<FieldRef Name='DayEvaluat'/>";

                objQuery.ViewFieldsOnly = true;

                SPList objList = objWeb.Lists["Job Desc"];

                SPListItemCollection oCollection = objList.GetItems(objQuery);
                DataTable table = new DataTable();

                foreach (SPListItem item in oCollection)
                {

                    SPFieldUrlValue hyper = new SPFieldUrlValue(item["DayEvaluat"].ToString());
                    item["Day Evaluat"] = hyper.Description;
                    
                    table = oCollection.GetDataTable();
                }
                return table;

            }
        }
I written above code, Please tell where is the problem in my code.

September 8th, 2015 2:33am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics