0

我想将具有 5 列的数据绑定到我准备的每个标签中。例如:

(row1,col1) 绑定到 label1 (row1,col2) 绑定到 label2

我的数据库中的行数可以变化,可以是 5 行、6 行等。列正好是 5。能帮我看看后面的代码吗?当用户按下按钮时,我需要绑定它。

这是我的aspx代码

<div style="margin-top:10px; border:solid 2px #7bc1f7; border-radius:20px; padding:10px;"> 
    <p>
        <asp:Label ID="lbl_semester" Text="Semester" runat="server" Height="20px" Width="100px"></asp:Label>:
        <asp:TextBox ID="txt_semester" runat="server" Height="20px" Width="20px"></asp:TextBox>
    </p>

    <p>
        <asp:Label ID="lbl_nama" Text="Nama" runat="server" Height="20px" Width="100px"></asp:Label>:
        <asp:TextBox ID="txt_nama" runat="server" Height="20px" Width="220px"></asp:TextBox>
        <asp:ImageButton ID="find_btn1" runat="server" ImageUrl="~/Images/search-icon.png" Height="20px" Width="20px" ImageAlign="AbsMiddle" />
    </p>

    <p>
        <asp:Label ID="lbl_nim" Text="NIM" runat="server" Height="20px" Width="100px"></asp:Label>:
        <asp:TextBox ID="txt_nim" runat="server" Height="20px" Width="220px"></asp:TextBox>
        <asp:ImageButton ID="find_btn2" runat="server" ImageUrl="~/Images/search-icon.png" Height="20px" Width="20px" ImageAlign="AbsMiddle" />
    </p>
</div>
<div style="margin-top:10px; border:solid 2px #7bc1f7; border-radius:20px; padding:10px;">
    <asp:Label ID="Label1" runat="server" Text="NO" Height="20px" Width="25px"></asp:Label>&nbsp;&nbsp
    <asp:Label ID="Label14" runat="server" Text="KODE" Height="20px" Width="85px"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Label ID="Label16" runat="server" Text="MATA KULIAH" Height="20px" Width="300px"></asp:Label>&nbsp;&nbsp;&nbsp;
    <asp:Label ID="Label17" runat="server" Text="SKS" Height="20px" Width="40px"></asp:Label>&nbsp;
    <asp:Label ID="Label18" runat="server" Text="NILAI" Height="20px" Width="300px"></asp:Label>&nbsp;&nbsp;&nbsp;
    <asp:Label ID="Label19" runat="server" Text="SKN" Height="20px" Width="35px"></asp:Label><br />

    <asp:Label ID="Label2" runat="server" Text="1" Height="20px" Width="25px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_kode_mk1" Text="-" runat="server" Width="85px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_mk1" Text="*****" runat="server" Width="300px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_sks1" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_nilai1" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_skn1" Text="-" runat="server" Width="20px"></asp:Label>
    <asp:CheckBox ID="CheckBox1" runat="server" Width="5px" /><br />

    <asp:Label ID="Label3" runat="server" Text="2" Height="20px" Width="25px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_kode_mk2" Text="-" runat="server" Width="85px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_mk2" Text="*****" runat="server" Width="300px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_sks2" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_nilai2" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_skn2" Text="-" runat="server" Width="20px"></asp:Label>
    <asp:CheckBox ID="CheckBox2" runat="server" Width="5px" /><br />

    <asp:Label ID="Label4" runat="server" Text="3" Height="20px" Width="25px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_kode_mk3" Text="-" runat="server" Width="85px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_mk3" Text="*****" runat="server" Width="300px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_sks3" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_nilai3" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_skn3" Text="-" runat="server" Width="20px"></asp:Label>
    <asp:CheckBox ID="CheckBox3" runat="server" Width="5px" /><br />

    <asp:Label ID="Label5" runat="server" Text="4" Height="20px" Width="25px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_kode_mk4" Text="-" runat="server" Width="85px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_mk4" Text="*****" runat="server" Width="300px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_sks4" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_nilai4" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_skn4" Text="-" runat="server" Width="20px"></asp:Label>
    <asp:CheckBox ID="CheckBox4" runat="server" Width="5px" /><br />

    <asp:Label ID="Label6" runat="server" Text="5" Height="20px" Width="25px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_kode_mk5" Text="-" runat="server" Width="85px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_mk5" Text="*****" runat="server" Width="300px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_sks5" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_nilai5" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_skn5" Text="-" runat="server" Width="20px"></asp:Label>
    <asp:CheckBox ID="CheckBox5" runat="server" Width="5px" /><br />

    <asp:Label ID="Label7" runat="server" Text="6" Height="20px" Width="25px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_kode_mk6" Text="-" runat="server" Width="85px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_mk6" Text="*****" runat="server" Width="300px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_sks6" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_nilai6" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_skn6" Text="-" runat="server" Width="20px"></asp:Label>
    <asp:CheckBox ID="CheckBox6" runat="server" Width="5px" /><br />

    <asp:Label ID="Label8" runat="server" Text="7" Height="20px" Width="25px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_kode_mk7" Text="-" runat="server" Width="85px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_mk7" Text="*****" runat="server" Width="300px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_sks7" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_nilai7" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_skn7" Text="-" runat="server" Width="20px"></asp:Label>
    <asp:CheckBox ID="CheckBox7" runat="server" Width="5px" /><br />

    <asp:Label ID="Label9" runat="server" Text="8" Height="20px" Width="25px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_kode_mk8" Text="-" runat="server" Width="85px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_mk8" Text="*****" runat="server" Width="300px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_sks8" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_nilai8" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_skn8" Text="-" runat="server" Width="20px"></asp:Label>
    <asp:CheckBox ID="CheckBox8" runat="server" Width="5px" /><br />

    <asp:Label ID="Label10" runat="server" Text="9" Height="20px" Width="25px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_kode_mk9" Text="-" runat="server" Width="85px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_mk9" Text="*****" runat="server" Width="300px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_sks9" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_nilai9" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_skn9" Text="-" runat="server" Width="20px"></asp:Label>
    <asp:CheckBox ID="CheckBox9" runat="server" Width="5px" /><br />

    <asp:Label ID="Label11" runat="server" Text="10" Height="20px" Width="25px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_kode_mk10" Text="-" runat="server" Width="85px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_mk10" Text="*****" runat="server" Width="300px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_sks10" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_nilai10" Text="-" runat="server" Width="20px"></asp:Label>&nbsp;&nbsp;
    <asp:Label ID="lbl_skn10" Text="-" runat="server" Width="20px"></asp:Label>
    <asp:CheckBox ID="CheckBox10" runat="server" Width="5px" /><br />
</div>   

4

1 回答 1

0

这是一个示例,如何循环gridview。

    double tot = 0;
    foreach (GridViewRow gvRow in GridView1.Rows)
    {
        Label lblGT = (Label)gvRow.FindControl("lblinvGrandTotal");
        if (lblGT.Text != "")
        {
            tot += Convert.ToDouble(lblGT.Text);
        }
    }
于 2013-08-18T13:16:21.250 回答