[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2010-11-21
9
Medium Priority
?
834 Views
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" 
                DataKeyNames="qAdventID">
               <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
               <Columns>
                   <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" />
               </Columns>
               <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" />
           </asp:GridView>

Open in new window

0
Comment
Question by:MHenry
[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
  • 6
  • 3
9 Comments
 
LVL 52

Accepted Solution

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

ReadOnly="true"

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:

    http://msdn.microsoft.com/en-us/library/bb288032.aspx
0
 
LVL 7

Author Comment

by:MHenry
ID: 34184754
carl_tawn,

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

0
 
LVL 7

Author Comment

by:MHenry
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 7

Author Comment

by:MHenry
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.
0
 
LVL 7

Author Comment

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

Expert Comment

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

Author Comment

by:MHenry
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

0
 
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.
0
 
LVL 7

Author Comment

by:MHenry
ID: 34192589
woo hoo!

thanks carl_tawn!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 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