Solved

Gridview in c# not updating

Posted on 2010-08-30
1
303 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XAML: Layout 8 25
c# string handling 1 26
How to avoid saving tif files a 2nd time using VS2015 and C#? 1 27
About delegates in c sharp 3 23
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

919 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

17 Experts available now in Live!

Get 1:1 Help Now