How to edit a single column in gridview? 2.0, vb, sql express

Posted on 2010-11-21
Last Modified: 2012-08-14
I want to be able to readout all columns in a table called qAdvent but allow insert/update of only one column. Is there a way to do this?

I would prefer that the column that performs the update contain a dropdown list with Yes and No as the choices. The underlying field is a text field that will have either yes or no.

Here's my gridview code. I don't know where to go from here.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 

               AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 

               DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" 


               <AlternatingRowStyle BackColor="White" ForeColor="#284775" />


                   <asp:CommandField ShowEditButton="True" />

                   <asp:BoundField DataField="quoteNum" HeaderText="quoteNum" 

                       SortExpression="quoteNum" InsertVisible="False" />

                   <asp:BoundField DataField="contract" HeaderText="contract" 

                       SortExpression="contract" />

                   <asp:BoundField DataField="location" HeaderText="location" 

                       SortExpression="location" />

                   <asp:BoundField DataField="serviceLevel" HeaderText="serviceLevel" 

                       SortExpression="serviceLevel" />

                   <asp:BoundField DataField="clientName" HeaderText="clientName" 

                       SortExpression="clientName" />

                   <asp:BoundField DataField="address1" HeaderText="address1" 

                       SortExpression="address1" />

                   <asp:BoundField DataField="city" HeaderText="city" 

                       SortExpression="city" />

                   <asp:BoundField DataField="itemName" HeaderText="itemName" 

                       SortExpression="itemName" />

                   <asp:BoundField DataField="serialNum" HeaderText="serialNum" 

                       SortExpression="serialNum" />

                   <asp:BoundField DataField="beginDate" HeaderText="beginDate" 

                       SortExpression="beginDate" />

                   <asp:BoundField DataField="endDate" HeaderText="endDate" 

                       SortExpression="endDate" />

                   <asp:BoundField DataField="annCost" HeaderText="annCost" 

                       SortExpression="annCost" />

                   <asp:BoundField DataField="proRateCost" HeaderText="proRateCost" 

                       SortExpression="proRateCost" />

                   <asp:BoundField DataField="flagForRemoval" HeaderText="flagForRemoval" 

                       SortExpression="flagForRemoval" />


               <EditRowStyle BackColor="#999999" />

               <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

               <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

               <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

               <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

               <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

               <SortedAscendingCellStyle BackColor="#E9E7E2" />

               <SortedAscendingHeaderStyle BackColor="#506C8C" />

               <SortedDescendingCellStyle BackColor="#FFFDF8" />

               <SortedDescendingHeaderStyle BackColor="#6F8DAE" />


Open in new window

Question by:MHenry
  • 6
  • 3
LVL 52

Accepted Solution

Carl Tawn earned 500 total points
ID: 34184425
making a single column editable is easy enough, you just need to add:


To all of the columns that should not be editable.

You will need to use a TemplateField for the column that should be a dropdown. This should get you started:

Author Comment

ID: 34184754

When I did it that way, it erased everything in the database by assigning everything as null except that one column.


Author Comment

ID: 34184759
I would also like to do this with a submit button instead of as an edit field. That way I can send an email notification when it has been updated if at all possible.

Author Comment

ID: 34184876
ah. convertEmptyStringToNull needs to be set to false.

anyway to do this with a button though? Really need to send a notification email.
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.


Author Comment

ID: 34184982
still stripping out everything even with the convertEmptyStringToNull set to false...
LVL 52

Expert Comment

by:Carl Tawn
ID: 34186072
What update command are you using for your SqlDataSource?

Author Comment

ID: 34188669
I used the standard thing inserted by vs2010
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:adventConnectionString %>"


            SelectCommand="SELECT * FROM [qAdvent] ORDER BY [quoteNum] DESC, [contract] DESC" 

            DeleteCommand="DELETE FROM [qAdvent] WHERE [qAdventID] = @qAdventID" 

            InsertCommand="INSERT INTO [qAdvent] ([dbDate], [quoteNum], [contract], [location], [serviceLevel], [clientName], [address1], [city], [itemName], [serialNum], [beginDate], [endDate], [annCost], [proRateCost], [flagForRemoval]) VALUES (@dbDate, @quoteNum, @contract, @location, @serviceLevel, @clientName, @address1, @city, @itemName, @serialNum, @beginDate, @endDate, @annCost, @proRateCost, @flagForRemoval)" 

            UpdateCommand="UPDATE [qAdvent] SET [dbDate] = @dbDate, [quoteNum] = @quoteNum, [contract] = @contract, [location] = @location, [serviceLevel] = @serviceLevel, [clientName] = @clientName, [address1] = @address1, [city] = @city, [itemName] = @itemName, [serialNum] = @serialNum, [beginDate] = @beginDate, [endDate] = @endDate, [annCost] = @annCost, [proRateCost] = @proRateCost, [flagForRemoval] = @flagForRemoval WHERE [qAdventID] = @qAdventID">

Open in new window

LVL 52

Expert Comment

by:Carl Tawn
ID: 34189883
Ok, because you are deviating from the IDE generated code you will need to manually tweak the UPDATE statement and it's associated parameters to exlude the columns that you want to have as read only.

So, remove each column name (enclosed in []) and each associated parameter (things starting with @), and then remove the corresponding elements from the <UpdateParameters> element. You need to leave the [qAdventID] column in there though because that is the key used for performing the update.

Author Comment

ID: 34192589
woo hoo!

thanks carl_tawn!

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

12 Experts available now in Live!

Get 1:1 Help Now