从Gridview的Cell获取数据(不使用标签或文本框)并在VB.Net中更新到数据库

时间:2015-01-08 10:22:11

标签: vb.net gridview rows itemtemplate

我从数据库中获取数据并在Gridview中填充。现在我有更新按钮。我希望当我点击该按钮时,它将从Gridview的每个单元格中获取数据并在数据库中更新它。我在从Gridview的Cell中获取数据时遇到了问题。

我已经绑定了以下代码,但它给了我空字符串:

Protected Sub btn_update_Click(sender As Object, e As EventArgs) Handles btn_update.Click

For t As Integer = 0 To GridView1.Rows.Count - 1
        Label1.Text += GridView1.Rows(t).Cells(1).Text.ToString()
    Next
End Sub

在浏览器视图中显示数据的位置(附图像)

enter image description here 以下是我的Gridview代码:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:TemplateField HeaderText="Roll_No">
                <ItemTemplate>
                    <%#Eval("Roll_No")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="COLLEGE ROLL NO.">
                <ItemTemplate>
                   <%#Eval("cRollNo")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="STUDENT">
                <ItemTemplate>
                    <%#Eval("cName")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="FATHER NAME">
                <ItemTemplate>
                    <%#Eval("fName")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="REGN NO.">
                <ItemTemplate>
                    <%#Eval("Reg_No")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="MARKS">
                <ItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" MaxLength="2" Width="40px"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Is Absent">
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
        <SortedAscendingCellStyle BackColor="#FDF5AC" />
        <SortedAscendingHeaderStyle BackColor="#4D0000" />
        <SortedDescendingCellStyle BackColor="#FCF6C0" />
        <SortedDescendingHeaderStyle BackColor="#820000" />
    </asp:GridView>

0 个答案:

没有答案