Created
November 8, 2012 15:27
-
-
Save rfessler/4039463 to your computer and use it in GitHub Desktop.
GridView -sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<asp:GridView runat="server" ID="GridView1" CellPadding="4" ForeColor="#333333" GridLines="None" | |
OnRowDataBound="_GridViewLogs_RowDataBound" AutoGenerateDeleteButton="True"> | |
<RowStyle BackColor="#EFF3FB" /> | |
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> | |
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> | |
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> | |
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> | |
<EditRowStyle BackColor="#2461BF" /> | |
<AlternatingRowStyle BackColor="White" /> | |
<Columns> | |
<asp:BoundField HeaderText="Column1" DataField="Data" /> | |
</Columns> | |
</asp:GridView> | |
'Declare a dictionary on the class level: | |
Private rowIndexer As New Dictionary(Of String, Integer)() | |
'Then, once the RowDataBind event fires for the first time make the indexer:' | |
If e.Row.RowType = DataControlRowType.Header Then | |
rowIndexer = New Dictionary(Of String, Integer)() | |
Dim i As Integer = 0 | |
While i < e.Row.Cells.Count | |
Dim cell As TableCell = e.Row.Cells(i) | |
rowIndexer.Add(cell.Text, i) | |
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1) | |
End While | |
End If | |
'That’s it! Now, all you need to do for example to hide row is to call the following line on the RowDataBind event: | |
e.Row.Cells(rowIndexer("ndtID")).Visible = False | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment