【问题标题】:display data in gridview在gridview中显示数据
【发布时间】:2011-04-01 06:11:39
【问题描述】:

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

大家有什么想法吗?

表中的数据就是这样存储的

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   

谢谢

【问题讨论】:

  • 如果您找到了解决方案,您能否将其发布为答案?它可能会帮助遇到类似问题的其他人。
  • 我没有使用上述模式,我已经改变了一切......这就是原因

标签: c# asp.net gridview


【解决方案1】:

我认为您可以使用中继器控件来执行此操作..

MSDN link转发器页面original link

【讨论】:

    【解决方案2】:

    在 GridView 上使用 Repeater 控制将使您能够更好地控制输出的格式。

    【讨论】:

      【解决方案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>
      

      代码

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

      【讨论】:

      • 谢谢 Magnus。如果这个问题Entity 带有 linq?我正在使用 vs2005。
      • QuestionEntity 只是一个例子,可以是任何东西。例如,如果您使用 DataTable 绑定 GridView,则为 DataRow。但是您可以使用 IEnumerable Answers 属性创建自己的 QuestionEntity 类,并从 Linq 查询中返回。
      猜你喜欢
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-16
      • 2014-02-21
      • 1970-01-01
      相关资源
      最近更新 更多