?
Solved

Using GridView (VB)

Posted on 2014-12-03
6
Medium Priority
?
101 Views
Last Modified: 2014-12-04
First off, can this be done. If so, where is an example or tutorial...

I'm using a GridView control in an ASP.Net page to display a list of records retrieved via a SQL Server stored procedure. This part is currently working.

The following I need to try and work out:

The GridView displays 9 columns. The first three columns need to be just display (no edit). The next 4 columns are checkboxes, the final two columns are fully editable. Currently these columns are read-only (that is, click on a checkbox and nothing happens). I need the user to be able to change the values in columns 4 through 9 and then save them.

Back to the question(s). Is this possible? How?

TIA
0
Comment
Question by:Clifton Bardwell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 40479103
You need to put in the gridview in edit mode to update the fields. CheckBoxes are read-only until then. The fields that you don't want them to change should have this ReadOnly="True" in the tag.

 <asp:BoundField DataField="Vol" HeaderText="Vol" ReadOnly="False" ControlStyle-Font-Size="Small"
   SortExpression="Vol" DataFormatString="{0:C2}" ItemStyle-HorizontalAlign="Right" ControlStyle-Width="90px"/>

This needs to be in the gridview wherever you want the Edit button:
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" ><ControlStyle CssClass="HyperLinkBlack" /></asp:CommandField>

See these links for examples:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview(v=vs.110).aspx

Checkboxes:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkboxfield(v=vs.110).aspx

Bounds Fields:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield(v=vs.110).aspx
0
 

Author Comment

by:Clifton Bardwell
ID: 40479233
Well, I was hoping for something a little more automated.  The user wants to be able to check boxes and add notes without having to click an "Edit" link for each row they are working on, then click an "Update" link before they can move to the next row.
0
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 40479533
You can use template fields and update from a button click. I couldn't find an example with a textbox, but here are a couple with checkboxes,

<asp:TemplateField SortExpression="Append" HeaderText="Append">
   <ItemTemplate>
   <asp:CheckBox ID="cbAppend" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem,"Append")%>' visible="true" />
   </ItemTemplate>
   </asp:TemplateField>
   <asp:TemplateField SortExpression="Delete" HeaderText="Delete">
   <ItemTemplate>
   <asp:CheckBox ID="cbDelete" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem,"Delete")%>' visible="true" />
   </ItemTemplate>
   </asp:TemplateField>

Open in new window

0
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 2000 total points
ID: 40479554
Here are my methods for appending and deleting records.
Protected Sub btnAppend_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim sp As String = String.Empty
        Dim statusCode As String = String.Empty
        Dim cb As String = String.Empty

        sp = "APO.usp_moveData"
        statusCode = APPEND_STATUS
        cb = "cbAppend"
        updateDataEntry(statusCode, cb, sp)
    End Sub

    Protected Sub btnDeleteMarked_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim sp As String = String.Empty
        Dim statusCode As String = String.Empty
        Dim cb As String = String.Empty

        sp = "APO.usp_deleteData"
        statusCode = DELETE_STATUS
        cb = "cbDelete"
        updataDataEntry(statusCode, cb, sp)

    End Sub

    Protected Sub updateDataEntry(ByVal newStatus As String, ByVal cbName As String, ByVal spName As String)
        Dim key As Integer
        Dim MyCheckBox As CheckBox
        Dim gv As GridView = gvData
        Dim projectdbo As New ProjectDataBO

        For Each Item As GridViewRow In gv.Rows
            MyCheckBox = CType(Item.FindControl(cbName), CheckBox)
            If MyCheckBox.Checked Then
                Dim index As Integer = Item.RowIndex

                key = gv.DataKeys.Item(index).Value
                If Len(key) > 0 Then
                      projectdbo.update_Data(key, newStatus, spName)

                End If
            End If
        Next
        Response.Redirect("Data_Form.aspx", False)
    End Sub

Open in new window

0
 

Author Closing Comment

by:Clifton Bardwell
ID: 40481019
Thanks.  :-)
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question