Skip to main content

ASP.net GridView CheckBox

Ancient piece of code that I keep forgetting.

<asp:GridView ID="grdR" runat="server" AutoGenerateColumns="False"
            DataKeyNames="Id" style="margin-left: 6px; font-size: x-small;" Font-Size="Small">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField SelectText="Edit" ShowSelectButton="True" />
                <asp:BoundField DataField="Length" HeaderText="Length" />
                <asp:BoundField DataField="Breadth" HeaderText="Breadth" />
            </Columns>
            <EmptyDataTemplate>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; There is no Value&nbsp;&nbsp;&nbsp;&nbsp;
            </EmptyDataTemplate>
        </asp:GridView>

    Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim i As Integer
        ' Dim bidlist(grdR.Rows.Count) As Integer
        For i = 0 To grdR.Rows.Count - 1
            Dim cbgrd As CheckBox = CType(grdR.Rows(i).FindControl("CheckBox1"), CheckBox)
            If (cbgrd.Checked) Then
                Dim rowId As Integer = grdR.DataKeys(grdR.Rows(i).DataItemIndex).Value
          ' do what you want

            End If
        Next

Comments

Popular posts from this blog

Siemens Washing Machine : Kill the Buzzer

The washing machine we have has the habit of sending out an irritating beep after it finishes the wash cycle. Ok enough; but these intermittent beeps go on and on and on till it is sure everyone came back home after your attending your funeral. One awful engineer who programmed the chip. Anyway, been looking around the net if there is a work around. Found this written by some Russian. I didn’t have patience to correct the grammar entirely. If the below does  not work, there is always the option of an Axe and ‘hey Siemens,..Heeeere is Johnyyy!) -- text You can change the volume of the buzzer according to your requirement. The operation procedure: 1. Switch on the machine,turn the program selector to Off . 2. Turn the program selector to cold Easy-care , press the additional function button Intensive stains and dont let go. You can hear the volume of the buzzer from minimum to maximum to off cycled (I didnt hear this!). If you decide the volume that you wa

HTML Sidebar menu without jQuery

Most examples I found on the net for a responsive sidebar had a reference to jQuery. For two lines of code, I find it an unnecessary overhead. So this is a basic page with no dependencies that has a toggle-able sidebar as well as a media query javascript that hides the sidebar below a breakpoint screen width. Modify as necessary. Maybe tricks could be added such as the one to change the hamburger to X when the sidebar is visible. https://jsbin.com/romiqov/2/edit?html,output <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>SideBar test</title>     <style>         * {             margin: 0;             padding: 0;             font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;         }         #sidebar {             position: fixed;             width: 200px;             height: 100%;             top: 50px;             left: 0px;             transition

Sudoku Puzzle Generator

Sudoku puzzles can be generated by a switching the rows and columns of a valid puzzle. The switch has to be done between the 123, 456 and 789 rows/columns. ie; 1 cannot be switched with 7 for example. A random pair can be generated and if a loop is run say 50 times, we get a new puzzle. Then the cells can be hidden again randomly. The following code generates the puzzle from a base character string which is converted to a 81 length Char array. The output is the solution as well as the puzzle with blank (or 0s)               Dim stdArray As String = "317849265245736891869512473456398712732164958981257634174925386693481527528673149"         Dim charArray() As Char = stdArray.ToCharArray         Dim rng As New Random         Dim m As Integer         Dim row1 As Integer         Dim row2 As Integer         Dim col1 As Integer         Dim col2 As Integer         Dim i As Integer         Dim cell1 As Integer         Dim cell2 As Integer         Dim tempC A