Solved

Using GridView (VB)

Posted on 2014-12-03
6
100 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

717 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