Solved

Using GridView (VB)

Posted on 2014-12-03
6
92 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
  • 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now