.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

SPFieldUser in a SPGridView

Posted By:      Posted Date: September 03, 2010    Points: 0   Category :SharePoint
Does anyone know how to add a SPFieldUser column to an SPGridView with the online presence? I'm hoping it would be similiar to the code below that adds a BoundField to a SPGridView BoundField colClient = new BoundField(); colClient.DataField = "Client"; colClient.HeaderText = "Client"; colClient.SortExpression = "Client"; oGrid.Columns.Add(colClient);  

View Complete Post

More Related Resource Links

SPGridView Not Appearing When Rows Exist


I have added the contents of a DataTable to an SPGridView control.  When there are no rows in the DataTable it shows the message "There Is No Data" which is correct. 

When there are rows in the DataTable the SPGridView does not appear at all.

What could the issue be?

The code is below:

DataTable gridTable = new DataTable();
gridTable.Columns.Add("Assigned To");

queryDPM.ViewFields = "<FieldRef Name='AssignedTo'/>" +
					  "<FieldRef Name='RequestDPMReviewerComments' />" +
					  "<FieldRef Name='WorkflowOutcome' />";

sQueryStr = "<Where>" +
				 "<And>" +
					"<IsNotNull>" +
					 "<FieldRef Name='RequestDPMReviewerComments' />" +

SPGridview Sub Menu


Hi All,

How to add sub menu for the spgridview? I have used SPMenuField for displaying context menu.

But how to add sub menu for the context menu (for eg., Send To-->Download a copy, In this how to add "Download a copy" to "Send To" template).

Let me know if you have any queires.


Thanks in advance,


SPGridView Paging In Webpart

I'm working on making results display web part and I'm displaying things using an SPGridView.  Things are working fine, except that I can't get the paging to work correctly.

The paging controls are displaying, but when I click to the next page, it reloads the page I'm on and I loose my results (basically the data isn't getting sent to the next page).  Below is the code I have:

Button cmdSearch;
        TextBox txtQueryText;
        DropDownList scopesDropDown;
        Label lblQueryResult;
        SPGridView grdResults;

        protected override void CreateChildControls()
            // Create and add the controls that make up the
            // user interface of the web part. 

            scopesDropDown = new DropDownList();


            txtQueryText = new TextBox();

            cmdSearch = new Button();
            cmdSearch.Text = "Start Search";
            cmdSearch.Click += new EventHandler(cmdSearch_Click);

            lblQueryResult = new Label();

        void cmdSearch_Click(object sender, EventArgs e)

Can not show image in Filter drop down menu in SPGridView - Sharepoint 2007

Hi, I can not show image in the filter drop down menu (at header) of SPGridView in Sharepoint 2007.  For example: I have 3 rows as "_layout/images/1.gif", "_layout/images/2.gif", "_layout/images/3.gif". When user click on the column's header, the SPGridView just displayed filter menu and it always displayed the text (_layout/images/1.gif) not an image as I expected. So please help me to solve this problem. Thanks a lot Dan

SPGridView Header

Is it possible to work with the alignment in a spgridview.  Do any of the properties work? Tried Vertical alignment (Top, Bottom, Middle) - None of these work Tried adding spaces to force new line before the header since it overlays the boundaries of the header, these do not work. (spaces are truncated). Tried adding HTML characters, this does not work. (<br />, &nbsp;). Do any of the SPGridView header properties actually work? 

SPGridview with ButtonField - Button does nothing

Could you please help me? I am using VS 2008 to build a web part that uses a SPGridView to display regions (from a SP list) that are associated with the current user (sUsername). The target system is MOSS 2007. When the user selects a region, I want to hide the SPGridview, display the region selected and pass the sUsername and sRegion to the next web part. The problem is, when the user clicks on the button, nothing happens. I have tried adding handlers for RowCommand and SelectedIndexChanging - but neither causes the target Sub to be executed. I have tried using the RowCommand and SelectedIndexChanging alone with different button types. Here is the code. This is within RenderContents because I am checking _provider to get the data from the previous web part. Why won't the Subs defined in the handlers execute? THANK YOU! ' set up data source for spGridview Dim dataSource As New DataTable() dataSource.Columns.Add("Region", Type.GetType("System.String")) Dim sRegion As String ' add items from list that match For Each ListItem As SPListItem In listRegion.Items    If ListItem("Emp").ToString() = sUsername AndAlso _         ListItem("Region") IsNot Nothing Then      sRegion = ListItem("Region").ToString()      igListDS = igListDS + 1  &n

How to access and cutomize group row in a grouped SPgridView

hi all! Is there any way to access and cutommize the grouped row of an SPGridView  --This is the row that display grouped value ! I can access all other row types such as : header row, datarow, footer row.. but i do not know to to access and custommize the grouped row... here the example code:This code set all value of all cell in SPgridView to "ABC"  when binding to datasource except grouped row     public void Rowdatabound(object sender, GridViewRowEventArgs e) {   foreach (TableCell cell in e.Row.Cells) {    cell.Text = "ABC"; }     }      

Dynamic menu item in MenuItemTemplate (in SPGridView)




I am implementing a SPGridView in a webpart and would like to have dynamic row menus (with different menu items) based on some cell values. It seems that the answer is in the very-poorly documented property HiddenScript of a MenuItemTemplate object, which contains a custom javascript function which should return true if the menu item should be hidden, or false otherwise.


My question is - how do I pass arguments to this custom javascript function? This is how the sample code looks like:


SPMenuField colMenu = new SPMenuField();

colMenu.HeaderText = "Address";

colMenu.TextFields = "url";

colMenu.MenuTemplateId = "PresenterListMenu";

colMenu.NavigateUrlFields = "url";

colMenu.NavigateUrlFormat = "{0}";

spgridview RowDataBound event returning cell values as empty


i am working with SPGridView to display Announcements. User should be able to edit his own created Announcements.Remaining Items shouldnt be having edit option.

i created SPGridView Columns :

                SPBoundField Title = new SPBoundField();
                Title.HeaderText = "Title";
                Title.HeaderStyle.Font.Bold = true;
                Title.DataField = "Title";

                SPBoundField Description = new SPBoundField();
                Description.HeaderText = "Description";
                Description.DataField = "Description";


SPGridView and SPMenuField

I have created a Webpart which contains List. Also, in that I am sucessfully able to create a menu field in Sharepoint 2010 . Now my problem is that the first column of my list is Task Title (SPMenuField) now when I click on the title which is hyperlinked I wish to open the display form in modalPopUp window which is only possible if i use javascript which is not possible in menufield.NavigateUrlFormat. HoweverI am sucessfully able to use javascript in the menu items of the MenuTemplate. Please help me get through this.

Please follow these steps to understand the exact issue:

Step2: See the above site . When I click on Kirst Wark (hyperlink and not the items in drop down)

Combining lists from multiple sites into SPGridview


I have one main SharePoint site which has 5 child sites. Each child site represents a different department. On each of these sites there is a list called "ActionPlans". These lists all have the same name and the same number of columns. I need to somehow combine the 5 "ActionPlans" from the child sites into one on the main page.

I was able to loop through the SharePoint object and pull out one list, populate a datatable and display it in the SPGridview. I am having problems looping through the other sites and combining all lists.

Please help, Ninel

Date formatting in SPGridview


How can I format the date from 9/23/2010 12:00:00 AM to 9/23/2010 in an SPGridview?

Thanks, Ninel

Get SharePoint list view functionality on SPGridView


I am trying to create a single view for all the list items (assume from three lists) within a site. I have retrieved the data through SPSiteDataQuery. But couldn't get the look and feel of the SharePoint list view initially. So I have tried using "SPGridView" instead of "GridView" and applied styles of the SPListView. But the problem here is,

The data i retrieved are all plain texts. When I use <SharePoint: ListView> and <SharePoint:ListViewByQuery> i am able to get the SPListView look and feel as well as the list items properly. But using these controls I could only able to get the list items from only one list at a time. Is this a limitation?

Note: I am trying to fetch the fields like "Title", "Created by", "Created Date" which is common and available in all the lists.

Vijayaragavan, MCTS

How to change th SPGridView Expand/Collapse images


Hi All,

How I can change the SPGridView Expand/Collapse Image for a SPGridView, By default it will display the "plus and minus" images, I want to use my own image insteadof this, Please let me the solution.



SPGridView grouping not working with sorting or paging


Anybody can help with the issue here? I have a SPGridView using ObjectDataSource with grouping, sorting and paging enabled. Once i clicked on the next button or the sort header, it's give the "An unexpected error has occurred." on screen. 

Error in the 12 hive logs
Application error when access /Web Pages/TestGridView.aspx, Error=Value cannot be null.  Parameter name: container
at System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName)
at Microsoft.SharePoint.WebControls.SPGridView.OnRowCreated(GridViewRowEventArgs args)
at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
at Microsoft.SharePoint.WebControls.SPGridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
at System.Web.UI.Control.EnsureChildControls()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()

Paging in SPGridView in Webpart



I am writing a share-point web part to perform search. So user inputs the keyword and i search from different servers and present him the results in Grid View along with paging. To accomplish this i started with different articles and finally wrote following piece of code, which so far is unable to handle paging. It shows the first result but for all other pages , naha, nada, empty ,


So here is the elegant piece of code , i got from googling ..




 #region variables
    DataTable MainDT = null;  
    private SPGridView grid;
    private ObjectDataSource gridDS;
    private LinkButton btnSearch;

 protected sealed override void CreateChildControls()
btnSearch= new LinkButton();
        btnSearch.Text = "Search";
        btnSearch.Click += new EventHandler(btnSearch_Click);

Modifying MenuItemTemplate property in SPGridView using RowDataBound event


In a nutshell, I have a SPGridView using a visual web part in SP2010.  I've added it to the user control like so (SPMenuField not shown):

<SharePoint:MenuTemplate ID="TitleMenuField" runat="server">
  <SharePoint:MenuItemTemplate ID="menuitemtemplate1" runat="server" Text="Edit Post"></SharePoint:MenuIt
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend