在gridview中显示数据

时间:2011-04-01 06:11:40

标签: c# asp.net gridview

我希望以图像中的格式在Gridview中显示数据。

任何想法的人?

enter image description here

表中的数据以这种方式存储

Qsn1    A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train?  Option1 150 metres  5   
Qsn1    A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train?  Option1 152 metres  5   
Qsn1    A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train?  Option1 154 metres  5   
Qsn1    A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train?  Option1 155 metres  5   

谢谢

3 个答案:

答案 0 :(得分:1)

我认为你可以使用转发器控制来做到这一点..

MSDN link转发页面original link

答案 1 :(得分:0)

对GridView使用 Repeater 控件可以让您更好地控制格式化输出。

答案 2 :(得分:0)

ASPX

<asp:GridView runat="server" ID="gv1">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <%# Eval("Question") %>
                    <asp:RadioButtonList runat="server" ID="rbl1" DataTextField="Name" DataValueField="QuestionID"></asp:RadioButtonList>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

代码

gv1.RowDataBound += (s, ev) =>
                    {
                        if (ev.Row.RowType == DataControlRowType.DataRow)
                        {
                            var rbl1 = (ListControl)ev.Row.FindControl("rbl1");
                            rbl1.DataSource = ((QuestionEntity)ev.Row.DataItem).Answers;
                            rbl1.DataBind();
                        }
                    };