Solved

Using GridView (VB)

Posted on 2014-12-03
6
87 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.  :-)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

11 Experts available now in Live!

Get 1:1 Help Now