[英]hide a specfic row in DataGrid asp.net using VB
This seems pretty easy to anyone but i cannot search on how to hide a speficic row in DataGrid(Not GridView) in asp.net using vb. 这对任何人来说似乎都很容易,但是我无法使用vb搜索如何在asp.net中的DataGrid(Not GridView)中隐藏特定行。 When i was searching, i only saw on how to hide a column using DataGrid1.Columns(0).Visible = False.
当我搜索时,我仅看到如何使用DataGrid1.Columns(0).Visible = False隐藏列。 I tried hiding it using ItemDataBound event but it hides the whole column along with its headercolumntext.
我尝试使用ItemDataBound事件将其隐藏,但是它将整个列及其标题列文本都隐藏了。
My aim is to search data with using a textbox where Date = textboxdate.text. 我的目标是使用日期= textboxdate.text的文本框搜索数据。 This is easy to do in sql but i cannot revise the query because it is in a stored procedure.
这在sql中很容易做到,但是由于它在存储过程中,因此我无法修改查询。
This is my current code: 这是我当前的代码:
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
I want to make something like this. 我想做这样的事情。
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 page: 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>
Add this Lines 添加此行
<asp:DataGrid ID="DataGrid1" runat="server"
OnItemDataBound="DataGrid1_ItemDataBound"
CellPadding="4" EnableModelValidation="True"
ForeColor="#333333" GridLines="None"
AutoGenerateColumns="False">
IN Code Behind 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.