我无法使用html获取多个记录 [英] i am not able to fetch multiple records with html

查看:110
本文介绍了我无法使用html获取多个记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我如何通过循环使用html获取多个记录



can anybody please help me how to get multiple record through loop with html

for (i = 0; i < ds.Tables[0].Rows.Count; i++)
{
    //Label3.Text = dr["name"].ToString();
    Label3.Text = ds.Tables[0].Rows[i]["name"].ToString();
    Label4.Text = ds.Tables[0].Rows[i]["actor"].ToString();
    Label5.Text = ds.Tables[0].Rows[i]["film"].ToString();

}







这是html






this is html

<form id="form1" runat="server">
   <div id="divmain" runat="server">
   <table>
               <tr>
               <td style="width:100px"><asp:LinkButton  ID="Label3" runat="server"

                       onclick="Label3_Click" ></asp:LinkButton></td>

               <td style="width:100px"><asp:LinkButton ID="Label4" runat="server" ></asp:LinkButton></td>
               <td style="width:100px"><asp:LinkButton ID="Label5" runat="server" ></asp:LinkButton></td>
               </tr>
           </table>
   </div>



   </form>






每次获得最后一条记录




getting last record every time

推荐答案

您使用的是重复记录的相同标签。所以记录将使用当前记录进行迭代和更新。最后,您将只看到最后的记录值。



要解决您的问题,您需要有一个gridview或listview控件来列出多个记录。



- >只有3个标签来显示多个记录是不够的。

- >你必须动态创建标签并添加到你的页面或使用上面指定的任何控件。
you are using the same labels with repeated records. so the records will be iterated and updated with the current record. And at last you are going to see the last record values only.

To address your problem, you need to have a gridview or listview control to list multiple records.

-> Having only 3 labels to display multiple records is not sufficient.
-> either you have to create labels dynamically and add to you page or use any control specified above.


你当然是。



这是因为你正在改变循环内的控制文本。因此,当循环迭代时,控件的文本正在改变,但是一旦循环终止,就会有最后一条记录。



所以你需要有多个控件显示这些数据或者可能使用gridview,listview,datalist等。



在aspx中试试这段代码:

Of course you are.

It is because you're changing the control text inside the the loop. So as the loop iterates, control's text is changing but as soon as the loop gets terminated, there you are with the last record.

So you need to have multiple controls to show this data or maybe use gridview, listview, datalist etc.

Well try this code in aspx:
<table>
        <% for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
          {%>
        <tr>
            <td>
                <%
                  Label3.Text = ds.Tables[0].Rows[i]["name"].ToString();
                  Label4.Text = ds.Tables[0].Rows[i]["actor"].ToString();
                  Label5.Text = ds.Tables[0].Rows[i]["film"].ToString();
                }%>
            </td>
        </tr>
</table>



-KR


-KR


这篇关于我无法使用html获取多个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆