Solved

Gridview in c# not updating

Posted on 2010-08-30
1
304 Views
Last Modified: 2012-06-27
Pretty simple though but not working :S

 i have a gridview bound to sqldatasource with update command but for some reasons on updating a row does not seem to work. Attaching my code in code part.
Thanks
<asp:GridView ID="gvStudentPersonal" runat="server" DataSourceID="ds_StudentDetail"
                    AutoGenerateColumns="False" DataKeyNames="MatricNo" AutoGenerateEditButton="True">
                    <Columns>
                        <asp:BoundField ReadOnly="true" HeaderText="MatricNo" DataField="MatricNo" SortExpression="MatricNo" />
                        <asp:BoundField HeaderText="Email" DataField="Email" />
                        <asp:BoundField HeaderText="DateOfBirth" DataField="DateOfBirth" />
                        <asp:BoundField HeaderText="Active" DataField="Active" />
                        <asp:BoundField HeaderText="Repeating" DataField="Repeating" />
                    </Columns>
                </asp:GridView>


 <asp:SqlDataSource ID="ds_StudentDetail" runat="server" ConnectionString="<%$ ConnectionStrings:EnterpriseValeConnectionString %>"
        SelectCommand="SELECT [MatricNo], [Email], Convert(varchar(50),[DateOfBirth],104) DateOfBirth,  [Active], [Repeating] FROM [Student] WHERE ([MatricNo] = @MatricNo)"
        UpdateCommand="Update Student Set Email=@Email,DateOfBirth=@DateOfBirth,Active=@Active, Repeating=@Repeating where MatricNo=@MatricNo">
        <SelectParameters>
            <asp:SessionParameter DefaultValue="0" Name="MatricNo" SessionField="MatricNo" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>

Open in new window

0
Comment
Question by:mmalik15
1 Comment
 
LVL 22

Accepted Solution

by:
Om Prakash earned 500 total points
ID: 33556873
you can add OnUpdated="OnUpdHandler" handler in SqlDataSource to see data is populated correctly..

example


<asp:Label
          id="Label1"
          runat="server">
      </asp:Label>

 <asp:SqlDataSource  ..other parameters..
 	        	OnUpdated="OnUpdHandler">

code behind

 Sub OnDSUpdatedHandler(ByVal source As Object, ByVal e As SqlDataSourceStatusEventArgs)
    If e.AffectedRows > 0 Then 'set a status label 
        Label1.Text = "data modified successfully.."
    Else 
        Label1.Text = "No data updated!"
    End If
 End Sub 

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
daypilot scheduler 3 26
Reference issues in Visual Studio 3 30
How to close an asp.net web form using C# ? 4 30
C# bracket error 3 30
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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