Solved

Gridview in c# not updating

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 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