display data in gridview

泄露秘密 提交于 2019-12-14 02:07:29

问题


i want to display data in Gridview in a format like in the image.

any ideas folks?

the datas in table is stored in this way

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   

thank you


回答1:


I think you could use the repeater control to do that..

MSDN link to repeater page original link




回答2:


Using Repeater contorl over GridView Will give you more control over formating your output.




回答3:


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>

Code

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();
                        }
                    };


来源:https://stackoverflow.com/questions/5509765/display-data-in-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!