0
下午好。我能夠將數據填充到vb.net中的DataGrid控件中。但是,從第一個下拉列表中選擇不同的公司時,會出現空行。這是因爲每個選擇的結果都是輸出數據網格中的所有報告,但只顯示適合公司的報告,因此那些不合適的報告保留爲空。但是,我被困在如何隱藏這些空行。我看過其他來源,但沒有工作。我如何隱藏空行?隱藏DataGrid中的空行
這裏是我的後端:
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
DropDownList2.Items.Clear()
'DropDownList2.Enabled = False
'DropDownList3.Enabled = False
'TextBox1.Enabled = False
If DropDownList1.SelectedIndex > 0 Then
Dim sConstr As String = ConfigurationManager.ConnectionStrings("ds17701ConnectionString").ConnectionString
Dim Conn As New SqlConnection(sConstr)
Dim ds As New DataSet()
Dim dt As New DataTable
Dim valsql As String = ""
Dim valsql1 As String = ""
Dim ds_Reports As New DataSet()
Dim parentitem As DataRow
Dim childitem As DataRow
'populates membership status once company selected
valsql = "SELECT [CompanyID], [CompanyName], [MemberTypeID], [MembershipStatus], [GroupID] FROM CompanyList WHERE COMPANYID = " & DropDownList1.SelectedValue
valsql1 = "SELECT REPORTID, REPORTNAME, REPORTCODE FROM REPORTLIST WHERE ReportVisible = 1"
valsql1 = valsql1 & ";SELECT c.ReportID, c.COMPANYID, rl.ReportName FROM CompanyReportListTable c, ReportList rl WHERE c.reportid = rl.ReportID and rl.ReportVisible = 1 and CompanyID = " & DropDownList1.SelectedValue
Using Conn
Conn.Open()
Dim comm As New SqlCommand(valsql, Conn)
Dim da As New SqlDataAdapter(comm) 'da serves as the new sqldataadapter for my sqlcommand
da.Fill(ds)
'da.Fill(dt)
da.SelectCommand.CommandText = valsql1
da.Fill(ds_Reports)
End Using
ds_Reports.Relations.Add("CompanyReport", ds_Reports.Tables(0).Columns("ReportID"), ds_Reports.Tables(1).Columns("ReportID"))
valGrid1.DataSource = ds_Reports.Tables(0)
valGrid1.DataBind()
For i = 0 To ds.Tables(0).Rows.Count - 1
If ds.Tables(0).Rows(i).Item(3).ToString = "M" Then
DropDownList2.Items.Insert(0, "Member")
DropDownList2.Items.Insert(1, "Non-Member")
TextBox1.Text = "M"
Else
DropDownList2.Items.Insert(0, "Non-Member")
DropDownList2.Items.Insert(1, "Member")
TextBox1.Text = "NM"
End If
Next
Else
DropDownList2.Items.Clear()
DropDownList3.Items.Clear()
TextBox1.Text.ToString()
DropDownList1.Items.Clear()
End If
End Sub
...我的DataGrid的前端。任何幫助,將不勝感激。
<asp:DataGrid ID="valGrid1" runat="server" AutoGenerateColumns="false" BorderWidth="0">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:DataGrid id="valgrid2" runat="server" AutoGenerateColumns="false" BorderWidth="0" datasource='<%#Container.DataItem.Row.GetChildRows("CompanyReport")%>'>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# IIf((Container.DataItem("ReportID")).ToString().Equals(""), "false", "true")%>'/>
<asp:Label ID="lblRptName" runat="server" Text='<%# ((Container.DataItem("ReportName")).ToString())%>'></asp:Label>
<asp:Label ID="lblReportID" Visible="false" runat="server" Text='<%# Container.DataItem("ReportID") %>' />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>