[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

Get checked checkbox values in a gridview

Dears,

I have a GridView that shows id, username, add_permission, edit_permission. In this gridview add_permission, edit_permission are checkbox fields. Now if any one press submit button as shown in the image then need to get  Id, checked checkbox values

Attached code also.  My code is asp.net with VB
<asp:GridView  ID="GridView1" CssClass="nomaltext" Width="99%" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
            BackColor="White" BorderStyle="None" BorderWidth="1px" CellPadding="3" BorderColor="#999999" GridLines="Vertical">
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id"  InsertVisible="False" ReadOnly="True" SortExpression="Id" />
                <asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
                <asp:TemplateField >
                <ItemTemplate >
                add permission
                <asp:CheckBox ID="chAdd" runat="server" />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField >
                <ItemTemplate >
                Edit permission
                <asp:CheckBox ID="chEdit" runat="server" />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField >
                <ItemTemplate >
                Delete permission
                <asp:CheckBox ID="chDelete" runat="server" />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField >
                <ItemTemplate >
                View permission
                <asp:CheckBox ID="chView" runat="server" />
                </ItemTemplate>
                </asp:TemplateField>                
            </Columns>
            <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
            <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="Gainsboro" />
        </asp:GridView>
        <asp:Button ID="Button1" runat="server" Height="45px" Text="Button" Width="74px" />


and code behind is 

        Dim dbConn As SqlConnection
        Dim DSList As DataSet
        Dim DAList As SqlDataAdapter
        Dim sqlString As String

        sqlString = "select id, username from Users"
        dbConn = New SqlConnection(ConnString)
        dbConn.Open()
        DAList = New SqlDataAdapter(sqlString, dbConn)

        DAList.SelectCommand.CommandTimeout = 300

        DSList = New DataSet
        DAList.Fill(DSList)

        If DSList.Tables.Count > 0 Then
            If DSList.Tables(0).Rows.Count > 0 Then
                GridView1.DataSource = DSList.Tables(0)
                GridView1.DataBind()

            End If
        End If

        dbConn.Close()
        dbConn.Dispose()

Open in new window

GridView.JPG
0
mshaji
Asked:
mshaji
  • 2
1 Solution
 
miketonnyCommented:
you can use something like this,  after setting flag when you update your database you can use flags to determine whether or not to insert that column's value
 
  Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        For i As Integer = 0 To dgv.Rows.Count - 1
            If dgv.Rows(i).Cells(2).Value = True Then 'Checked
                  set flag
            Elseif dgv.Rows(i).Cells(3).Value = True Then 'Checked
                 set flag
            Elseif dgv.Rows(i).Cells(3).Value = True Then 'Checked
                 set flag
            Elseif dgv.Rows(i).Cells(3).Value = True Then 'Checked
                 set flag
            End IF
  
        Next

        End If
    End Sub

Open in new window

0
 
mshajiAuthor Commented:
done
0
 
mshajiAuthor Commented:
ok
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now