开发者

Options for Displaying Data in table format

Options for Displaying Data in table format

Hi

I want to display the data in the format that is represented in the screenshot. All the data that is shown is retrieved from Sql Server-2005 Database. Which is the best option for such kind of data representation? I have read in the forums, from them I could not get a clear perspective. Some were suggesting listview others nested datagrid, some repeater control. Can you please suggest me which one would be a proper and accurate way to go forward ?? Along with some reasons (if possible !!). And I'm using visual studio 2008, .net Framework 3.5, asp.net with c# and I'm NOT using LINQ in my project and it is a web application. The same picture can also be found at http://postimage.org/image/2xj9bdles/

Thanks in anticipati开发者_如何学Con


You can definitely do this with a ListView and nested Gridviews. There is nothing tricky about it.

I suggest you start with a ListView and just make the parent rows (ie: the grey bar rows.) From there you can add in your nested GridViews.


Sorry, just a shot in the dark. Did you try Telerik controls? Not free, unfortunately...


Whenever I'm faced with data that needs to be represented in a complex table format I default to using the Repeater control. I've even started using Repeater for simple tables as well. Why Repeaters? You get to completely (and easily) control the output. Which allows for some pretty complex arrangements, and also allows for lightweight HTML for simple grids.


I think you need to take a look outside of the box. Right now you are only exploring server controls. While convenient, they lack the ability to be customized in a practical manner.

You can easily build this table in your code behind with a string builder with unlimited control and less code.

Here is an example that uses LINQ for the datasource, but you could modify it for yours.

StringBuilder sb = new StringBuilder();

sb.Append( "<table class='tableStripe'>");
sb.Append( "<tr><th width='1%'>Active</th><th>Image</th><th>Name</th><th>Short Description</th><th>Source</th><th width='1%'>Date Created</th><th width='1%'>Data Modified</th></tr>");

foreach (var result in join)
{
    string chk = (result.Brand.Active ? "checked='checked'" : "");
    sb.AppendFormat( @"<tr><td><input class='brandChk' value='{4}' type='checkbox' {0}>
                       </td><td width='1%'><img width='50px' src='{1}'</img></td>
                       <td><a href='/admin/Catalog/Brand/Detail.aspx?brandId={4}'>{2} 
                       </a></td><td width='60%'>{3}</td>", chk, result.Brand.Image,
                       result.Brand.Name, result.c,result.Brand.BrandID);
    sb.Append("<td>");
        foreach (var q in result.Sources)
        {
            string srcname = (q.Source1=="Motovicity" ? "Motovicity":"Direct");
            sb.AppendFormat("<img src='{0}' title='{1}'</img>", q.Image,srcname);
        }
        string date = string.Format("{0:MM/dd/yy}", result.Brand.DateCreated);
        string mod = string.Format("{0:MM/dd/yy}", result.Brand.DateModified);

    sb.Append("</td>");
    sb.AppendFormat("<td>{0}</td><td>{1}</td></tr>", date, mod);
}
sb.Append("</table>");
resultSpan.InnerHtml = sb.ToString();

This example is a lot more complex than what you're probably looking for, but it should get it's point across.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜