我尝试将网格视图加载到预先存在的网格视图中,因此布局与此类似:
Branch Account Name Type Sub Hold LOC
central 1234 John sc s 5000 20
Financial Gridview for above account would appear here
Branch Account Name Type Sub Hold LOC
central 1234 Jane sc s 1000 20
Financial Gridview for above account would appear here
And so on....
在财务网格视图中,我会显示所有帐户持有人的财务状况。我希望通过在信息的另一个gridview中加载来完成此操作,但是当它尝试将其添加时我遇到以下错误:无法设置列' branch'。该值违反了此列的MaxLength限制。
我的LoadData方法如下:
Private Sub LoadData()
conn = New SqlConnection(connectionString)
ds = New DataSet("Accounts")
da = New SqlDataAdapter("SELECT [branch], [no] , [surname], [name], [type], [sub], [totalAmount], loc, HoldCalc, odTimes " & _
"FROM [DmdOD]", conn)
Dim branchQuery As String = "central"
Dim gridFinance As New GridView
If ListBranch.SelectedItem IsNot Nothing Then
branchQuery = ListBranch.SelectedItem.ToString()
End If
conn.Open()
da.FillSchema(ds, SchemaType.Source, "Accounts")
da.Fill(ds, "Accounts")
Dim tblAccounts As DataTable
tblAccounts = ds.Tables("Accounts")
Dim dsFinance = New DataSet("Finance")
Dim dsFinanceTemp = New DataSet("FinanceTemp")
Dim daFinance = New SqlDataAdapter()
Dim tblFinance As DataTable
Dim tblFinanceTemp As DataTable
tblAccounts = DeleteDuplicateFromDataTable(tblAccounts, "no")
'Loop through to find financial information for each account
For Each row As DataRow In tblAccounts.Rows
Dim rowNo As Integer = row.Item("no")
daFinance = New SqlDataAdapter("SELECT branch, no, effective, desc_, code, empltype FROM [DmdOD] where no =" & rowNo, conn)
daFinance.FillSchema(dsFinance, SchemaType.Source, "Finance")
daFinance.Fill(dsFinance, "Finance")
daFinance.FillSchema(dsFinanceTemp, SchemaType.Source, "FinanceTemp")
Dim newRow As DataRow = dsFinanceTemp.Tables("FinanceTemp").NewRow()
newRow("branch") = "central"
tblFinance = dsFinance.Tables("Finance")
tblFinanceTemp = dsFinanceTemp.Tables("FinanceTemp")
For Each finRow As DataRow In tblFinance.Rows
'count the rows to load into the dataTable
Dim rowCount = (From r As DataRow In tblFinance.Rows Where CType(r("no"), Integer) = rowNo Select r).Count()
Do While finRow.Item("no") = rowNo And rowCount <> 0
tblFinanceTemp.ImportRow(finRow)
rowCount -= 1
Loop
Exit For
Next
gridFinance.DataSource = tblFinanceTemp
gridFinance.AutoGenerateColumns = True
gridFinance.Attributes.Add("style", "table-layout:fixed; position: relative; z-index: 1")
gridFinance.Height = 400
gridFinance.Width = 200
gridFinance.BorderWidth = 2
gridFinance.DataBind()
'this is the line the error is happening on
tblAccounts.Rows.Add(gridFinance)
Exit For
Next
GVAccounts.DataSource = tblAccounts
GVAccounts.DataBind()
conn.Close()
End Sub
主要Gridview的代码:
<asp:GridView ID="GVAccounts" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333"
GridLines="None"
style="position: relative; margin-top: 10px" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="branch" HeaderText="Branch"
SortExpression="branch" />
<asp:BoundField DataField="no" HeaderText="Account"
SortExpression="account" />
<asp:TemplateField HeaderText="Name" SortExpression="name">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("name") + " " + Eval("surname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="type" HeaderText="Type" SortExpression="type" />
<asp:BoundField DataField="sub" HeaderText="Sub" SortExpression="sub" />
<asp:BoundField DataField="TotalAmount" HeaderText="Hold"
SortExpression="TotalAmount" />
<asp:BoundField DataField="loc" HeaderText="LOC" DataFormatString="{0:c}" SortExpression="loc" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
我试过谷歌搜索将gridview放入gridview。我也试过谷歌搜索我已经得到的错误,但也没有任何运气。任何见解都将不胜感激。