Reputation: 159
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. When i was searching, i only saw on how to hide a column using DataGrid1.Columns(0).Visible = False. I tried hiding it using ItemDataBound event but it hides the whole column along with its headercolumntext.
My aim is to search data with using a textbox where Date = textboxdate.text. This is easy to do in sql but i cannot revise the query because it is in a stored procedure.
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:
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>
Upvotes: 0
Views: 1395
Reputation: 10275
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
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
Upvotes: 1