Gridview Column as Row
On an ASP NET project I have a gridvi开发者_如何学JAVAew control with the following information:
Column A Column B Column C Graph
Value A 1 9 Graph A
Value B 3 7 Graph B
The graph column has a Chart control on each row being that the information o each chart represents the values of eack row, for example, Graph A has a bar chart whith 10% and 90% and Graph B has a bar chart with 30% and 70%.
No what I would like to know is the easiest way to represent information like this:
Column A Column B Column C
Value A 1 9
Graph A
Value B 3 7
Graph B
Thanks
Use a TemplateField for Column B. Then you can use any HTML you like there. For example:
<asp:TemplateField HeaderText="Column B" >
<ItemTemplate>
<asp:Label runat="server" ID="LblColumnB" /><br/>
<asp:Image ID="ImgChart" runat="server" />
</ItemTemplate>
</asp:TemplateField>
You can bind the Data for example in GridView's RowDataBound-Handler.
void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
var data = (DataRowView)e.Row.DataItem;
var LblColumnB = (Label)e.Row.FindControl("LblColumnB");
var ImgChart = (Image)e.Row.FindControl("ImgChart");
// Bind data or load the controls ....
}
}
精彩评论