簡體   English   中英

使用VB在DataGrid asp.net中隱藏特定行

[英]hide a specfic row in DataGrid asp.net using VB

這對任何人來說似乎都很容易,但是我無法使用vb搜索如何在asp.net中的DataGrid(Not GridView)中隱藏特定行。 當我搜索時,我僅看到如何使用DataGrid1.Columns(0).Visible = False隱藏列。 我嘗試使用ItemDataBound事件將其隱藏,但是它將整個列及其標題列文本都隱藏了。

我的目標是使用日期= textboxdate.text的文本框搜索數據。 這在sql中很容易做到,但是由於它在存儲過程中,因此我無法修改查詢。

這是我當前的代碼:

 If txtAdmDate.Text <> "" Then

        If Not String.Equals(txtAdmDate.Text, e.Item.Cells(0).Text) Then
            e.Item.Cells(0).Visible = False
        End If

    End If

我想做這樣的事情。

    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
    If txtAdmDate.Text <> "" Then
        If DataGrid1.Row(0).text <> txtAdmDate.Text Then
            DataGrid1.Row(0).Visible = False
        End If
    End If
End Sub

ASPX頁面:

Search By Date:
 <asp:TextBox ID="txtAdmDate" runat="server"></asp:TextBox>
 <asp:Button ID="btnSearch" runat="server" Text="Refresh / Search" />
<br />
<asp:DataGrid ID="DataGrid1" runat="server" CellPadding="4" EnableModelValidation="True" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False">
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
    <Columns>
        <asp:BoundColumn DataField="Admission Date" HeaderText="Admission Date"></asp:BoundColumn>
        <asp:BoundColumn DataField="Hospital #" HeaderText="Hosp. #"></asp:BoundColumn>
        <asp:BoundColumn DataField="Admission #" HeaderText="Reg. #"></asp:BoundColumn>
        <asp:BoundColumn DataField="Patient Name" HeaderText="Patient Name" Visible="false"></asp:BoundColumn>
        <asp:ButtonColumn DataTextField="Patient Name"  HeaderText="Patient Name" CommandName="Select"></asp:ButtonColumn>
        <asp:BoundColumn DataField="Discharged Date" HeaderText="Discharged Date"></asp:BoundColumn>
        <asp:BoundColumn DataField="Billing Date" HeaderText="Billing Date"></asp:BoundColumn>
    </Columns>
</asp:DataGrid>

添加此行

<asp:DataGrid ID="DataGrid1" runat="server" 
OnItemDataBound="DataGrid1_ItemDataBound"
 CellPadding="4" EnableModelValidation="True" 
ForeColor="#333333" GridLines="None" 
AutoGenerateColumns="False">

IN代碼背后

Protected Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
     Dim Row As DataGridItem
    Row = DataGrid1.Item

    ' Dim txbox As TextBox
    ' txbox = CType(Row.FindControl("txtbox"), TextBox)
    ' this for template fields Only

    'if you used BoundFields you can access like this

 If Not String.Equals(txtAdmDate.Text, Row.Cells(0).Text) Then
            Row.Visible = False
        End If


    End Sub 'Item_Bound 

' this will give you selected row 
' from this you can find controls on that row like text boxes,labels

資源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM