Welcome Guest Search | Active Topics | Sign In | Register

Grid Datasource as IEnumerable - display empty cells Options
Peter249
Posted: Friday, May 17, 2013 8:54:59 AM
Rank: Advanced Member
Groups: Member

Joined: 5/15/2013
Posts: 34
Hi I'm new to the grid, have followed documentation and samples, and have a problem with displaying data in the Grid. Should be easy but......

My web application has a service which goes out to a database and processes some tables (several un-joined) and returns a List<Thing> array of records. Each entry has an Integer property for ThingID, String property for ThingName, and String property ThingDescription as well as other stuff.

The concept is: The user wants to find things in a database and get a List<> of possible items to choose from. He/She then clicks the Grid row containing the Thing item of interest (record key is ThingID). The grid then posts back to the server for further processing of ThingID.

The grid has 3 columns 1 hidden and 2 visible -- the example Grid is read only items.

The grid displays the rows but where data should be they are empty cells.

Using ASP.NET 4.0, VS2012, linq, C#


Thing.cs - Items to display in grid

Code: C#
public class Thing
    {
       #region Properties

        public int ThingID { get; set; }
        public int OtherThingID { get; set; }
        public String ThingName { get; set; }
        public String Model { get; set; }
        public String Manufacturer { get; set; }
        #endregion

        #region Custom Properties

         public String ThingDescription
         {	get
              	{      return (String.Format ("{0} {1}", Manufacturer, Model));	
               }
          }

          #endregion
    }


Grid as defined in ThingControl.ascx file (I added KeyField -- made no difference)

Code: XML
<eo:Grid ID="Grid1" runat="server" Height="96px" Width="374px" BorderColor="#C7D1DF" BorderWidth="1px" ColumnHeaderAscImage="00050303" ColumnHeaderDescImage="00050304" ColumnHeaderDividerImage="00050302" FixedColumnCount="1" Font-Bold="False" Font-Italic="False" Font-Names="Verdana" Font-Overline="False" Font-Size="9pt" Font-Strikeout="False" Font-Underline="False" GridLineColor="199, 209, 223" GridLines="Both" ItemHeight="19" FullRowMode="False" KeyField="ThingID">
                    <ItemStyles>
                        <eo:GridItemStyleSet>
                            <ItemStyle CssText="background-color: white" />
                            <ItemHoverStyle CssText="background-image: url(00050206); background-repeat: repeat-x" />
                            <SelectedStyle CssText="background-image: url(00050207); background-repeat: repeat-x" />
                            <CellStyle CssText="padding-left:8px;padding-top:2px; color:#336699;white-space:nowrap;" />
                        </eo:GridItemStyleSet>
                    </ItemStyles>
                    <ColumnHeaderStyle CssText="background-image:url('00050301');padding-left:8px;padding-top:2px;font-weight: bold;color:white;" />
                    <Columns>
                        <eo:RowNumberColumn Visible="False"></eo:RowNumberColumn>
                        <eo:StaticColumn HeaderText="NAME" ReadOnly="True" Text="" Width="75"></eo:StaticColumn>
                        <eo:StaticColumn HeaderText="DESCRIPTION" ReadOnly="True" Width="-1"></eo:StaticColumn>
                    </Columns>
                    <ColumnTemplates>
                        <eo:RowNumberColumn DataField="ThingID">
                        </eo:RowNumberColumn>
                        <eo:StaticColumn DataField="ThingName">
                        </eo:StaticColumn>
                        <eo:StaticColumn DataField="ThingDescription">
                        </eo:StaticColumn>
                    </ColumnTemplates>
                    <FooterStyle CssText="padding-bottom:4px;padding-left:4px;padding-right:4px;padding-top:4px;" />
                </eo:Grid>


Code behind ThingControl.ascx.cs

Code: C#
public partial class ThingControl : UserControl
	{

		protected void BindData()
		{
			Grid1.DataSource = IoC.Resolve(IThingService).GetThings(); // return List&lt;Thing&gt;
			Grid1.DataBind();
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{	this.BindData();
			}
		}
	}
eo_support
Posted: Friday, May 17, 2013 12:37:02 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

You must set DataField inside Columns, not ColumnTemplates. The rest of your code is correct.

Thanks!
Peter249
Posted: Friday, May 17, 2013 1:43:48 PM
Rank: Advanced Member
Groups: Member

Joined: 5/15/2013
Posts: 34
new It had to be something simple -- Thanks it works just fine now


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.