Solved

Gridview in c# not updating

Posted on 2010-08-30
1
302 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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

6 Experts available now in Live!

Get 1:1 Help Now