Gridview项目未正确填充

时间:2015-06-22 23:45:00

标签: asp.net vb.net

我正在尝试将数据输入到gridview中。我正在查找gridview的行数并将数据添加到它们中:

我的测试"但是不会填充到Gridview中的Submitted和Variance BoundFields。所有人都是公司。不应该"测试"还填写其他两列?

Private Sub BindGrid()

    Dim dt As New DataTable
    dt.Columns.Add("Company")
    dt.Columns.Add("Submitted")
    dt.Columns.Add("Variance")
    gvTally.DataSource = dt


    Dim da As SqlClient.SqlDataAdapter
    Dim strSQL2 As String
    Dim Response As String = ""

    strSQL2 = "SELECT [Company] FROM [Monetra].[dbo].[tbl_MonetraLogins]"
    da = New SqlClient.SqlDataAdapter(strSQL2, System.Configuration.ConfigurationManager.AppSettings("MainConnectionString").ToString)
    da.Fill(dt)

    Dim dr As DataRow

    For i As Integer = 0 To gvTally.Rows.Count - 1

        dr = dt.NewRow
        dr.Item("Company") = dt.Rows(i).Item("Company")
        dr.Item("Submitted") = "test"
        dr.Item("Variance") = "test"

        dt.Rows.Add(dr)
    Next

    gvTally.DataSource = dt
    gvTally.DataBind()

End Sub

这是我的ASP网格:

<asp:GridView ID="gvTally" runat="server" EnableModelValidation="True" 
                    AllowSorting="True" class="table table-condensed table-striped table-bordered table-hover no-margin" AutoGenerateColumns="False" Font-Size="Small">
                    <Columns>
                        <asp:BoundField DataField="Company" HeaderText="Company" >
                        <ItemStyle Width="180px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="Submitted" HeaderText="Submitted" />
                        <asp:BoundField DataField="Variance" HeaderText="Variance" />
                        <asp:TemplateField HeaderText="Action" ShowHeader="False">
                            <ItemTemplate>
                                <asp:Button ID="Button1" runat="server" CssClass="btn btn-success btn-small hidden-phone" Text="View" CommandName="View" />
                            </ItemTemplate>
                            <ItemStyle Width="60px" />
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>

1 个答案:

答案 0 :(得分:0)

尝试使用此vb代码,然后注释掉我的测试

NULL