C# Writing a LIST to Datagrid

tmajor99
tmajor99 used Ask the Experts™
on
Is it possible to write a LIST to a datagrid?  I have a LIST that contains a list of attribute names that I want to display in datagrid row. For example sortedList:
attributeTtitle
  Color
  Size
  Length

I want to list this to a datagrid or some type of table so that the is aligned horizontally like this:
Color    Size    Length

Currently, I am writing this LIST to an EXCEL record like beow:
var sortedList = FilteredValueOfProduct.OrderBy(prod => prod.attributeTtitle).ToList();

            foreach (var item in sortedList)
            {
                HttpContext.Current.Response.Write("<Td>");
                //Get column headers  and make it as bold in excel columns
                HttpContext.Current.Response.Write("<B>");
                HttpContext.Current.Response.Write(item.attributeTtitle.ToString());
                HttpContext.Current.Response.Write("</B>");
                HttpContext.Current.Response.Write("</Td>");
            }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fernando SotoRetired
Distinguished Expert 2017
Commented:
It seems that this is an ASP.Net application. The following should do what you need, although I am not an ASP.Net programmer I remember doing it like this.

datagrid1.DataSource = FilteredValueOfProduct;
datagrid1.DataBind();
Alternatively, you could use repeater control. Make the RepeatDirection as horizontal to display the values horizontally. Sample code is given below:


Client side:

<asp:RadioButtonList runat="server" ID="myList" 
    CssClass="NormalTextBox" RepeatDirection="Horizontal">
    
</asp:RadioButtonList>

Server side:

myList.DataSource = FilteredValueOfProduct;
myList.DataBind();

Open in new window


HTH

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial